The Escape Button is a Feature

Marc Frappier
1 min readJul 30, 2023

--

Esc aping from our game

If we decide to build our game where it play in full screen mode, there is no way to exit the game short of force closing the window.

This is why we should give the player an option to exit the game using the Escape key.

To do this, we will use the GameManager script inside the Update method.

It is actually very simple to create.

We need to use an if statement, where we ask if the escape key has been pressed. If the answer is true, then we need to call the method that quits the game.

Inside the if statement, we will use Input.GetKeyDown(KeyCode.Escape)). This will check and see if the Escape key has been pressed.

If the escape key has been pressed, then the statement is true, we will need to execute or call the method Application.Quit(), this will cause the program to exit and close.

How to exit an application using the Escape key in a Unity build

NOTE: This will only work in a built version of the game and not while being played in the editor.

--

--

Marc Frappier

Poultry Scientist by profession, Computer Scientist at heart. After many years in the poultry business, I have decided to give my passion for technology a shot.