Implementing an Escape Button Feature in Your Unity Game

Objective: To give your game an ‘Escape’ button feature in Unity!

You have created your game, set up the build on your desktop to play in full windowed mode and now all of sudden you have no way of exiting out of the game! Like with everything else we have built in our game so far, we need to create the functionality of an ‘Escape’ button through code as it isn’t simply sitting there waiting for us to press it. Lucky for you this is one of the easiest features to create in a game, let’s get into it!

GameManager

This feature is one that we want to put within our ‘GameManager’ script as it is handling the state of our game. So let’s open it up and add this simple code:

Now if we press the ‘Esc’ key it Quits the Application!!

How cool and simple is that??

Just make sure that your Game_Manager game object is active in the scene and you have attached your ‘GameManager’ script to this.

Take a Step Further

You could then take this to the next level by allowing your ‘Escape’ key to take you to a new UI panel which holds different features of your game E.g. Settings, Credits, Instructions, Restart Game, Quit Game etc…

Have fun!

--

--

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