Day 92: Create an Elevator In Unity Part 1

Tyler Smallwood
3 min readNov 19, 2021

--

Objective: Create an Elevator Panel that will be used to call the Elevator.

Today we will focus on creating a system that will call the elevator. Tomorrow we will cover actually getting the elevator to move down.

We will start by creating the panel. For the prototype we will just create Cube with a Sphere as a child to the Cube.

We can add a Material on the Call_Button to red to show that it is not been used. For the Panel we will add a Box Collider and expand it so that it’ll read that the player is inside of it. The Box Collider will have IsTrigger set to true. We will have a Rigidbody with gravity set to 0.

We will now create a Elevator Panel script. To start off the script, we will have some SerializeFields’. We need one to change the Call_Button’s color when we call the elevator. We will need an int to control how much coins will be needed to use the elevator.

Next will to be use OnTriggerStay to watch for player input and to see if the player has met the right conditions.

When we check for input, we are also checking to see if the player has the right amount of coins to call the elevator. We just use the other.GetComponent<Player>() to grab a method that is on the player.

On the player script we have a method that allows other scripts to see the amount of coins the player is holding. The method is public so other scripts will be able to see it and all the method does is return coins.

Now to change the color of the Call_Button. If the player has met all the criteria, we will grab the material and color and assign it a new color.

All that is left is to assign the Call_Button to the elevator panel script.

Now we have the option to call the Elevator and when we do call the elevator the Call_button will now change colors. Tomorrow will be about moving the elevator down and going back up.

Thank you for reading and have a wonderful day!

--

--

Tyler Smallwood
Tyler Smallwood

Written by Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer

No responses yet