You can use the escape button to code a variety of logic such as pause menus, exiting full screen mode, or to cancel out an menu or selection. In this tutorial we’ll be covering using the escape button to close our application if not in full screen or out of full screen if full screened. This feature is most useful for games built out to PC, Mac, or Linux.
Start by opening a new project or existing project, create a new game object named Exit Manager and a script by the same name.
Below is the full commented code. We’ll step through it.
This is a relatively straight-forward script. If simply checks for a Escape key and if the screen mode is Full Screen it turns it off. Alternatively if it isn’t in full screen mode then it calls for the application to quit. Now build out your game and give it a swing. Should work without a hitch like below.
There you have it a very simple way to turn off full screen mode and if not quit your application in one fell swoop. Until next time, happy coding.