Escaping is a Feature

Alberto Garcia
1 min readJan 27, 2023

--

Closing an app, quitting, is not something naturally implemented into any game made with unity, it is a feature that must be implemented; if a game runs on full-screen mode without an implemented way to exit, one must restart the computer or phone to get out of the game. This is a quick way of allowing players to quit the game whenever they need to.

To do this, there is a new c# script called Game Manager which should be a singleton. In here there are two methods, the update constantly checking for player input to restart the core loop and exit the game, and below is the Game Over method that changes the boolean from true to false.

public class GameManager : MonoBehaviour
{
private bool _isGameOver = false;

void Update()
{
if (Input.GetKeyDown(KeyCode.R) && _isGameOver == true)
{
SceneManager.LoadScene(1);
}

else if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}

public void GameOver()
{
_isGameOver = true;
}
}

Using the escape key, players can now escape the eternal spawn of enemies and quit the app. Application.Quit() is something that cannot be tested inside the engine and must be tried on a build to notice correct functionality.

Esc escaping

--

--

Alberto Garcia
Alberto Garcia

No responses yet