- Home /
What is the best way to watch for button/key presses?
The way that I know to watch for a button press (I.e. bring up the menu of escape is pressed) is to create a script and to put if(Input.GetKeyDown()) into its Update() function.
Is this really the most efficient way to do this? Having to check every frame for a button press seems inefficient. Is there a way to put the script to sleep until a key is pressed? Or to just call a function whenever a key is pressed?
Basically I want to know if there is there a more efficient way to monitor for key presses than to check every frame if the button is pressed?
Answer by myzzie · Feb 01, 2019 at 10:20 PM
The best way as far as I'm concerned is to check every frame if any key is pressed with Input.anyKeyDown
and only then check if a certain key is pressed. This is something I'd use for example a hotkey setup 1 to 9 or similar.