How to quit your application with the press of a button.

addam davis
2 min readJun 16, 2021

--

Objective: Set a quit function to the ESC key.

Today’s lesson is an easy one. Today we are setting up the function of exiting an application with the press of the escape key. We want to add this feature so we can play our game in full screen mode. Without this function the only way to exit the game currently in full screen mode is the task manager.

First, what controls the status of the game? The game manager! we need to add this function to the game manager’s script.

This is an input function so we will need to write this code in the update method, and we will need to use an if statement.

The executable code is simple. It’s Application.Quit();

You may notice when you try to test this that in Unity the ESC exit doesn’t work. The only way to test this function is in the actual game build.

Go to file — build setting — and build.

If you go into the player setting and under the resolution select full screen.

Now when you load your game in full screen you can exit with ease with a simple press of the ESC key.

--

--

No responses yet