Elevator Lift

The next thing that we will create is a functioning lift system. The lift will switch between floors with a 5-second delay at each level.

First, let’s choose a prop that will be our lift.

We will move our elevator from point A to point B and it will stop for 5 seconds when reaching each point.

We need to create to empty GameObject for point A and B. To make it easier, I will just duplicate my elevator and move it to the position I want it to move to and from.

Then I will remove all the component, so they will become empty GameObjects.

The functionality will be similar to the moving platform we made before so we will use it and add a delay. Add the Moving Platform script we made before to our elevator.

Add the point A and B variables and set the speed. If you start the game, the elevator will be moving up and down. Now, we need to add a delay.

To add the delay we will use a coroutine. We will add to new variables _isPaused, to check if the elevator should move, and _delay that will tell us for how much time should the elevator stop moving.

In the FixedUpdate method, check the _isPause variable. If it is false, we will move the elevator. When we reach the target, we will change _isPause to true, and call the coroutine.

The new method is simple. When it is called, we will us WaitForSeconds to delay our elevator and then change _isPause to false to move the elevator.

In the Inspector change the delay variable to 5 and start the game.

--

--

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