Quick tip: The ESC key is a feature!

Escape the game!

Timo Schmid
2 min readMay 5, 2021
Photo by Ali Kazal on Unsplash

Okay, granted, that pun was horrible. Anyways, we should include a quick way for the player to close the game without the need of a separate Pause menu. This is done very quickly.

What do we need to do?
We just need to check whether the player is pressing the Escape key or not. If the escape key is pressed, then end the game. As the key press can happen at any time of the game, we need to check for it every single frame.

Implementing the logic
To check whether the Escape key was pressed or not, we need to access the Input Manager and check for the escape key. As we just want to execute the code when the key was pressed, we need an if-statement.

We want to close the application when the condition is met. As we don’t know the command triggering the closure of the application, we need to do a little research here. Simply searching for “close application unity” will reveal the command we need. Application.Quit().

Having found out the code we need, the if-statement now is:

That’s all we need! Pressing the ESC key will now close the game as soon as the player presses it.

--

--

Timo Schmid
Timo Schmid

Written by Timo Schmid

The mission? Becoming a game developer! RPG is the dream! Writing down my journey here for me and for everyone interested. Thanks for showing interest :)

No responses yet