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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Networking for DevOps

Snake Game

Enabling fans to discover their favorite team’s gear

Using Google Maps on Flutter for Android

Passwordless Authentication to Support Multi-Channel User Actions

Amazon Web Services — [ AWS ]

Scrum to the Rescue

In the SINWORLD metaverse, realize players’ dreams that cannot be achieved in real life 🔮

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
S.J. Jason Liu

S.J. Jason Liu

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

More from Medium

Working with Cinemachine

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 2)

Day 105: Working with Animation Events in Unity

How I used scriptable objects to build a powerup system