Elevator Lift 2.0- Game Dev Series 93
Objective: create an elevator with 5 seconds pause on each stop.
We’ve created a moving platform before. This time we will make the elevator as a routine moving platform with specific pause time on each stop.
Packing the lift
To make a platform moving between 2 position, we need to create 2 empty objects to storage the position information. However, we should make sure the lift is on the right position.
As you can see, my lift has a different pivot point which makes it on a weird position in game scene. To fix this issue, we can simply create an object and make the lift as its child.
Once packed the lift, it would be easy to make it moves.
Moving between stops
Create a new script and create 2 gameobject variables to storage the position, then create 2 empty in scene as destination.
Then create a Transform variable as target position.
Now we can create the moving method of lift.
In this script, I use switch statement with a bool to control the moving direction of lift.
Play it and you should see your lift as a moving platform.
5 seconds on each stops
To make it stopping at each stops for 5 seconds, we need to create a coroutine and a bool as switch.
In this coroutine, we will switch the bool of moving direction after 5 seconds waits.
Then we can call this coroutine after the lift is reached one of stops.
Since the moving method is in Update(), we don’t want it to call coroutine every frame. That is why we need the bool that we just created.
Add the bool into if statement and also switch it again in coroutine.
All done! Play it and enjoy the result!