Geek Culture
Published in

Geek Culture

2.5D Platformer: Setting up the Elevator, Part 1

In the next couple of articles, I’ll set up an elevator that the Player will call by pressing the “E” key near an elevator call panel.

First, I’ll be setting up the behavior of the panel. For example, I want the button to change color when the Player presses the “E” key, and also, I only want the “E” key to work if the player is near the elevator panel.

To detect when the Player is in front of the panel, I’ll use a Box Collider. Then in a script that I’ll add to the Elevator_Panel GameObject, I’ll use an OnTriggerStay() event to check if the Player is within the area.

Now that I have the script on the GameObject, I will create an OnTriggerStay() event, check if the collider is tagged as the Player, and check if the E key is pressed.

Next, to change the button's color, I’ll need to create a variable to reference it and then drag the object into the Inspector. I’ll create a variable of type Meshrenderer since that will give me direct access to the material then the object's color.

Now I need to drag the Call_Button object into the Inspector to access it further in the script.

Finally, to change the color of the Call_Button, I need to go into the script and add the line to change the color when the E key is pressed.

When Igo in front of the elevator panel and push the E key, the button will turn green.

That is it for the first part of setting up the elevator. Next article, I will add another requirement for the Player to have collected 8 coins for the elevator button to work.

So until next time, I wish you well on your own coding journey.



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