The Escape Button is a Feature

Exiting the Game

Google search for Escape Key Image. Found this Couldn’t help myself

There is no escaping the Game once it is started in full screen mode.

I need a way to exit the game the best way to do that is to have a Game Manager in the game that will quit the game when the Escape key is pressed while the game is running.

I have Been using Unity’s Input Manager for all of the other user inputs so I created an Exit Game that I can use.

Edit->Project Settings->Input Manager

Add a new Axis called Exit Game Make it use the Escape Key.

How do I exit a Game in code?


Quits the player application.

Shut down the running application. The Application.Quit call is ignored in the Editor.

This works if I build the Game, but what about if I am in the Editor Testing?


Is editor currently in play mode?

Setting isPlaying delays the result until after all script code has completed for this frame.

Ok so I have a method that I can use if I am not using the Editor(The Game has been built) and a bool that I can change the value to false if I am using the Editor(pressed the play button in Unity).

Testing Things Out

It works when I am in the Editor.

Windows Build

Now lets see if it works when I do a Windows Build.

Setting the Player to use Full Screen and Building the Game.

It does indeed exit when doing a Windows build.

How about A WEBGL Build

It does not work as intended, in a WebGL build it throws an error. This has to do with the way Web Browsers work.

I fixed this be adding an if for using WebGL Builds. In this case I decided to make the Application Open a Link to my web site.

Now when I do a build and run it takes me to my web site when I hit the escape key.




Excited about changing my hobby into a new carer with GameDevHQ course.

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

Recommended from Medium

From legacy Android app to a modern app architecture

about if if-else and conditional operator (AND&&,OR||, NOT! ) in programming language

Best MacOS tools in the day-to-day of a FullStack Developer

When Should You Hire A Team Of Front-end And Back-end Developers VS Full-Stack Developers?

Are You Implementing Robotic Process Automation or Anarchy

Algorithms In Python: Quicksort

You Can’t Build an iPhone With Python

Configure Named Pipe And TCP/IP Settings Of SQL Server

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
James Lafritz

James Lafritz

Excited about changing my hobby into a new carer with GameDevHQ course.

More from Medium

Over-The-Shoulder Aiming in Unity

Draggable UI In Unity

Mastering Unity Scripting | Summary — Chapter 3: Singletons, Statics, GameObjects, and the World

Guide to Making a Beautiful Game: Occlusion Culling