The Escape Button is a Feature

Renato Figueiredo
1 min readDec 12, 2023

Objective: Learn how to implement the quit functionality on the escape key.

So we have our game published, we have an executable for it, but at the current moment, the players cannot exit our game. They can, but only if the game is played on the Windowed mode, if played on Fullscreen, the player cannot do anything to go back to their desktop.

Our game currently has no way for the player to leave it.

Lucky for us, Unity has an easy way to fix this. We can add a functionality to our Escape key, that quits the application if the player presses it.

Application.Quit();

This command cannot be used in the editor, ’cause its specific to builds. This will effectively shut your game down and close the current window its in.
This is the functionality we wanted, so how do we implement this ?

Well, we had created a Game Manager, which manages the state of the game. Inside this class, we can check if the player pressed the Escape key, and if so, we exit the application.

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

Now with this implementation, when the player presses Escape, it will tell Unity to quit the application!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response