Press ESC to Quit- Game Dev Series 31

Objective: Add a function to quit game when press esc.

After we built our game, there is still one issue existing- couldn’t quit the game. We can simply add 1 line to code to solve this situation.

Open GameManager script, in Update() we can add a line to it.

Application.Quit() will handle exiting the game when player press escape when game over.

Besides that, we need to create a text UI to notice our player can press escape when game over.

Duplicate Restart_text and rename it as Exit_text, then drag it slightly under Restart_text. Then edit the text content.

Open UIManager script, add a new variable to storage Exit_text. Then disable & enable it in Start() and UpdateSprite().

Back to editor, drag the Exit_text into variable holder in Canvas.

After all the setting, you need to build the game again to check the function.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store