In this article, we are starting the process of creating an elevator by making a call button to detect when pressing a button and the elevator light changes color.
On the Elevator Panel game object, a Box Collider to extended so it can detect when the player has entered the collider.
Create a script and attach it to the Elevator Panel game object. We want to detect when the Player collides with that extend Elevator Panel collider meaning the Player is standing by the panel, we will use OnTriggerStay. Using OnTriggerStay detects when another game object is in the Collider, which is different than OnTriggerEnter, that only detects that one moment another game object enters the collider.
We check the other Collider’s tag and if it is the Player, we can check an input of the E key. Once this happens, we will change the color of the Elevator Button to green.
Getting Handle of Elevator Button
In order to change the color of the Elevator Button, we need to access the Mesh Renderer of that game object. In the script, we serialized a MeshRender variable.
Assign the Elevator Button in the inspector and now we have access to the Mesh Renderer.
Now we have a handle on the the Mesh Renderer, we can set the color to something else when E key is pressed.
In the next article, we are going to create a requirement of a certain amount of coins or a key in order to use the call button.