The Escape Button is a Feature
Exiting the Game
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.