Creating an Elevator (part 1)
Our task for the elevator function is going to require several parts to work together. The first condition is to have an total amount of 8 points to be able to call the elevator.
Then when the player reaches access point, we need a visual prompt to tell the player to push and certain key input (ie. pressing the “E” Key to activate the elevator) There will be several other user feedback including a Light which turns color.
Once the player is on the elevator, and only when the player is on the elevator will the elevator start to rise up.
With these steps lay outed, we will need to slowly implement these functions step by step.
The Elevator Panel:
Logically analyzing the break down of the elevator process, we should noticed that the elevator panel is the target for controlling and triggering everything including checking for collision of the player. Therefore we will place the majority of the scripts within this game object.
Create a new C# script and named it “Elevator Panel” and drag the script into the game object.
First we are going to focus on something simple, when the player reaches the Elevator Panel and presses the E button. We just want the red light to change to blue. To do this, we will rely on the On Trigger Stay method which basically triggers the set condition whenever the player is within the collider. Then we are going to check the other tag to see if it is the Player we are colliding with. Finally the final condition is checking for the E button input. When that button is pressed and only then, will the material for the light change color.
Back in Unity, once you drag in the Light object into the script slot, hit play to see if the color changes when all 2 conditions are met.
In the next article we will focus on activating the elevator.