How to implement Quit Button in Unity

Harvey Limbo
Apr 14, 2021

--

For today’s short article, I’ll be going over how to allow the player to quit the game by pressing the ESCAPE key.

Note: this is super useful only when the Unity game is a standalone build and especially when on full screen mode.

How to do it

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

Application.Quit() function will not work when playing the game from the editor. To test out the functionality, you must build a standalone executable of the game.

What it looks like in action

Thanks for reading!

--

--