Nerd For Tech
Published in

Nerd For Tech

Creating an Elevator in Unity

Now that we have our basics of the game set up, let’s go through and figure out how to add some more advanced features into the game. To start, we shall look at creating an elevator system that the player can use to reach unobtainable heights. What we shall do to start is get our player to be able to interact with the panel to call the elevator down:

For this situation, we need to use OnTriggerStay so that we can call it while we are within the trigger zone. Next, we will tell Unity that when we have press the ‘e’ button, we want the material colour of our button to change to green:

Now that we have our button changing colour, let’s get it set up so that when we collect a required amount of coin, we can activate the button.
What we will have to do is create logic to allow the elevator to know how many coins we want it to have before we can operate it. For this case, we are going to set it up as a modular method so that we can adjust the value for each different elevator system we put in place:

In order to be able to know how many coins the player has, we will need to create a new variable to work with that gives us the ability to set how many coins we want to have for the elevator. In order to know how many coins the player has, we need to create a link to the script and gather the value through a public int:

As for how we determine the value, we can set up a simple return method within our player script. Now that we have this in place, let’s see how it operates in the game:

Now that we have our panel working, let’s look at how we can create logic to allow the elevator to come down to the player so we can advance further. To start, we will need to create a script for our elevator and have it connected to our call button:

Once we have created that connection, we can go into our new script and create the logic needed to call down our elevator. The question becomes however, do we want our elevator to constantly move up and down on us freely once we activate it, or do we want to have it only move when we tell it to.
If we wanted it to move freely up and down, we can use the following code:

With this, we are essentially repeating the process of our moving platform, but before we allow it to move freely, we need to be sure that our CallElevator method is called first to allow our elevator to move freely:

Now that we have this method set up, let’s see how we would go about to make it so that we have to click ‘e’ to move up once we have gotten onto the elevator. The script that we will need for this will be slightly different, as we can create a few less steps for the process:

What we are doing here is toggling our bool statement on and off each time we call it. Rather than typing out a huge statement of switching it back and forth, this method uses up just 1 line. Next, we simply just tell Unity which target we want to go to depending on the statement.
Next, we need to make some adjustments within our panel script:

To give the game a small visual update when we call the elevator up or down, we will toggle our light between green and red. Other than that, we are just calling our elevator method every time we press the ‘e’ button:

Now when we are going up on this elevator, we can notice a small amount of shakiness. To fix this we simply just have to have the parenting process that we had with the moving platforms like before:

With that done, and a box collider added to our elevator, we can see if the player smoothly glides upwards:

There we have it, we now have a working elevator and worked on 2 different methods of making it move. Next up, we will look at how we can create a wall jumping mechanic.




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

VMware VSphere Integrated Containers: What, How, and Why

Clone of Nykaa Man using backend

Hacktop vs VM

5 Great Webflow Resource Sites For Your Next Project

Here’s my follow-up to REST is the new SOAP: let’s talk about the Original REST

Infrastructure as a Code using Terraform and AWS

Invictus Community AMA: UST, FRAX and Flare.

Starting with Docker-CLI

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
Jordan Evans

Jordan Evans

More from Medium

Basics of Optimization in Unity

Intro Physics with Unity

Adding proximity detection so enemies can ram player

Pokemon in Unity: Basics of Scriptable Objects