Making Elevators In A Unity Platformer

Today I’m building upon yesterdays “Moving Platforms” to make a callable elevator.

Press button, elevator comes, ride to the top!

Today’s Objective: Expand upon the existing automatically and continuously moving platforms to create an elevator which can be enabled and disabled.

The Design:

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.

The trigger collider is larger than the panel, and activates the text popup and input checks when player is inside it.

The Code:

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:

Input checks and function starts.
Toggle activation functionality.
Trigger zone entry and exit functionality.

Now by simply adding in whatever functions I want into the Inspector UnityEvents, I can make the button do anything for any cost:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store