Using the Escape button to Quit in Unity

Jaime
May 7, 2021

--

Well, to quit in Unity, you can simply run Application.Quit(). To be able to catch escape, simply listen to KeyCode.Escape.

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

That’s it! If you don’t want pressing Escape to just kill your game immediately, just add more conditions in the if statement.

To test quitting, you will need to build the game and run it from there. In my tests, it doesn’t work from the Unity Editor.

--

--

Jaime
Jaime

No responses yet