Creating Elevator in Unity — Part 1: Changing Button Color
Changing the elevator panel button color
Objective: change the color of the elevator panel button when the player presses the “E” key.
For this feature I created some prefabs, one is the elevator panel with a little button and the elevator prefab to move the player to the other section of the level. Also I created an elevator panel script and attached it to the prefab.
The logic to change the color of the button is to detect a trigger collision with the elevator panel, check for the player tag and if the user presses the E key, then change the color of the button.
In the script I declared a variable to have the reference to the mesh renderer component of the button. Then in the start method I used the Find function to get the button and the GetComponent function to get the mesh renderer.
Using the OnTriggerEnterFunction I created an if statement to check for the player tag, another if statement to check if the player pressed the “E” key and finally changed the color of the material in the mesh renderer of the button.
And that’s it!!! We changed the elevator panel button color when the player calls the elevator.