Framework 1: Creating an Elevator
Creating an Elevator system that works with a total point activation
Now that we created the mobile platform that can move towards to points back and forth, it is time to expand that ability. We are going to create and Lift system which can only be trigger when the player has a certain amount of points.
Preparing the Elevator and the Elevator Panel
The Elevator setup which I have is proudly provided by GameDevHQ’s Filebase courses. It comes with a lift, a back plate that provides an illusion of an elevator track and also an terminal.
On the terminal, we are quickly going to add a box collider which will be of larger size than the actual terminal. This is going to have the “is Trigger” checkbox selected because it is going to check for Player contact. Next I created an 3D capsule as an “light” indicator for player feedback.
Then I placed everything under an new empty game object which will house both objects.
As for the Elevator life, we are going to follow a very similar format as we did for the Moving Platforms. First we are going to isolate the life platform, then we are going to create two empty game objects which will be the target positions, and also an box collider surrounding the lift that will have the “is Trigger” checkbox selected.
We are going to create 2 C# scripts, one for the Elevator Control Panel, which will check if the player has enough points to activate the elevator, and also the ability to toggle the elevator movement. The second script will focus on the elevator lift itself, such as the movement.
The Elevator Panel Script:
First in the elevator panel, we are going to reference two variables, first to the light capsule, second the total required points to trigger the elevator.
Then we are going to create an reference to the Elevator lift script. Then in the start method you are going to find that script with an Get Component function.
Finally, we are going to add some functionality to the Control Panel. Since this will be our first time working on this script, there will be some functions which are mention here that you won’t be able to make reference to because they aren’t created yet. We will add them later.
Using the box collider, we are going to check for player contact and when the player does enter the collider, if the player had met the two set conditions, we will trigger the elevator movement, and also change the light from Default Red to Green.
In the player script, we are quickly going to add in the public method which was referenced by the Control Panel “total Points”. Since the player already has the points data, all we have to do is create a public method which we can return the value.
Elevator Lift Script:
In the elevator lift script which is attached to the actual Lift. We are going to first make several variables, one for the two target positions, one Float variable for the lift movement speed, and finally an bool for an future boolean switch.
Then we are going to create the public method which the Control Panel has reference “Call Elevator”. Within this public function we are going to define the starting position of the lift before movement, so it snaps into position. Then we are going to activate the boolean which we had set to false by default.
Next we are going to create a boolean switch that tells when the elevator should move. Just like how we script the mobile platforms, we will also use “Fixed Update” for the elevator as well. Using the If and else If statements we can write that when the boolean as been activated the lift would move from Target A to Target B. Else if, when the the switch has been deactivated it will move back towards the default position which is Target A.
Since this is also an moving object, we need to attach the player as a child game object of the platform to create that transition. Therefore similar to how we did the mobile Platforms, we use On Trigger Enter and On Trigger Exit. The only extra is that when the Player first makes contact on top of the platform, will that movement begin.
Back in Unity, drag all the necessary objects into the scripts (ie. Target positions A and B) and also the Light Mesh Renderer. Once you play, you should have an working elevator system which the player can only call when they have enough points.