Press ESC to Quit- Game Dev Series 31

S.J. Jason Liu
2 min readMay 26, 2021

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.

--

--

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.