Creating A Feature That Uses The Escape Button To Exit An Application

When you build your application if you have it set to Fullscreen mode then you leave the player having to manually exit your software using something like the “Task Manager”. To avoid this, you can add the ability to press the “Escape” key to exit the application.

This can be done very easily. Just make a game object that rests in your hierarchy such as a “GameManager” or whatever. This needs to be an object that is never deleted or removed from the game for whatever reason and if all else fails, just use an Empty Game Object.

Add a C# script to the above-mentioned object and just add the following code…


This feature will not work in the editor. This means that in order to test this out you will have to build a version of your project.



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
Adam Reed

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!