Hi guys,
how can I make a lamp in the ceiling turn on when I press E on a switch in a wall?
Thanks
Hi guys,
how can I make a lamp in the ceiling turn on when I press E on a switch in a wall?
Thanks
Take a look GetKeyDown to determine if āEā was pressed.
With regard to turning the light on or off, you can find the light in your scene using GameObject.Find, and setting its renderer component to enabled or disabled.
Edit : To determine if the player is within range of the switch, you can add a trigger to the area in front of the switch, and if the player is in that area, you know which switch/light to turn on/off.
Alternatively you can do a raycast from your players forward direction to determine if they are facing the switch, and check that in your script.