Rage Quit: Adding an escape
Objective: Allow player to exit game by pressing the escape key
In Unity there is a command Application.Quit() which will exit the game, but only in the build. Inside the GameManager script, this command is executed within void Update() after checking to see if the escape key has been pressed, as shown below. This command does not work in the editor, but can be used to exit windowed or full screen modes.
To test the feature create a standalone build and launch game using the executable, Andromeda Shooter.exe.
Below we see an example where the game has not gone well and it is time to rage quit. Pressing the escape key closes the window and the application.
Application.Quit() works well for the standalone version, but if you use this in a web build, for example on simmer.io, then the game just freezes. For WebGL build use the Application.platform command to check if the build is using the RuntimePlatform.WebGLPlayer. If the game is using the WebGL version then the SceneManager.LoadScene(0) returns the player to the main menu to allow them to restart the game, otherwise quits the application.
To see an WebGL example, try https://simmer.io/@hal/andromeda-shooter.