Elevators in 2.5D Environments.
Objective: Understand what all goes into creating an elevator and implementing.
What is an elevator? It is a platform that only moves when called upon. We need an object the player can interact with to call the elevator. The physical movement of the elevator is similar to the moving platform. This article we are going to focus on the player interaction with an elevator panel.
The elevator panel I am using a cube with a flattened red sphere child to it.
This panel needs a trigger script, so create a script and delete everything inside. We need an on trigger enter method and check for if the player collides with the panel.
What do we want to happen when the player is inside the elevator panel’s collider? We want to check for input from the player. I want the player to be able to hit the E key to activate the panel. I also want to set the limit that the player needs a set amount of coins to activate the panel.
Let’s begin with the input.
If we want the elevator panel to be able to check how many coins the player had we can create a return method on the player script.
With this, if the elevator were to call on this method the value of coins will be returned. Create an int variable for the elevator panel to set the limit for coins the player needs to call the elevator.
Now on the input check we can get the player script component and check if the player had the appropriate amount of coins.
I want a physical representation for when we called the elevator so I’m going to switch the light from red to green when we call it using a bool.
Now when the player reaches the elevator panel with the right amount of coins and pressed the E key, the panel will turn from red to green and we will call the elevator. In the next tutorial we will focus on the actual elevator movement. I’ll see you in the next Tutorial!