Making Elevators In A Unity Platformer
Today I’m building upon yesterdays “Moving Platforms” to make a callable elevator.
Today’s Objective: Expand upon the existing automatically and continuously moving platforms to create an elevator which can be enabled and disabled.
Following on from yesterday’s Medium, we already have an object which can move between any number of waypoints, and can be stopped via the “_movementEnabled” boolean. So to make it an elevator we simply need to make it able to be remotely activated, called, and deactivated.
For that purpose, I create a new object in the world to act as the remote elevator “button”:
The elevator panel, in this case, is a simple rectangle with a small sphere and a 3D TextMeshPro object as child objects. The sphere will change color on activation, and the text will show “Press E To Use” when the player is in range.
Now I create a new script called “WorldButton”. The idea with this component is not to force it to only be a elevator button, but instead design it to be modular and reusable.
For that reason, it uses UnityEvents rather than hard-coded commands. In this way, I can make it do anything upon activation:
First, the variables:
Then the functionality:
Now by simply adding in whatever functions I want into the Inspector UnityEvents, I can make the button do anything for any cost: