Day 32 | The Escape Button is a Feature

Ted Lim
1 min readMay 4, 2021

If you’ve created a local build of your Unity game on your computer, you may have noticed that if you play your game in fullscreen mode, you can’t quit the game using the Esc key. In this article, we’ll go over how to implement this feature.

Implementing the Escape Key Feature

If you have a GameManager script for your game or any other script that manages your game state, open it, and in the Update method, add the following code:

if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}

Now, when players press the Esc key, the game application will exit.

This is just a fun fact to know that some taken-for-granted features are still conscientiously programmed in by developers. Eventually, for a larger-scale project, you may want the Esc key to be reserved for opening a menu, which then will give you an option to exit the application by clicking on a Quit button. However, for smaller projects, you can map the Esc key or any other key of your choice to quit the game quickly.

--

--