Does anybody have a solution?
I’m trying to get the script to check if the door is open, if so pressing E will close it and vice versa.
if (Input.GetKey (KeyCode.E) && (gateOpen == false)) //check for key press
print ("e was pressed to open");
gateOpen = true;
if (Input.GetKey (KeyCode.E) && (gateOpen == true)) //check for key press2
print ("e was pressed to close");
gateOpen = false;
You probably want to use Input.GetKeyDown instead of
Input.GetKey. GetKey returns true on every frame as long as the key is held down, so your code will very quickly toggle back and forth between open and closed. GetKeyDown returns true only on the frame that the key was pressed, and won’t return true again until the key is released then pressed again. So this will give you a single press and your code will only toggle the door state once.
solved! it was an issue in my animation controller, the script left the opened and closed state as true so it created a loop.