Pausing the game
At this point, we have some issues. Once the menu is gone, there is no way to get it back, the game should start unpaused, and the game should actually pause. Let's tackle these issues next:
- Open up the
PlayerBehaviour
script and replace the bottom of the Update function with the following (changes are highlighted, note the removal of the original way of callingrb.AddForce
):
/// <summary> /// Update is called once per frame /// </summary> void Update () { // If the game is paused, don't do anything if (PauseScreenBehaviour.paused) return; // Movement in the x axis float horizontalSpeed = 0; // Check if we are running either in the Unity editor // or in a standalone build. #if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_EDITOR // Check if we're moving to the side horizontalSpeed = Input.GetAxis("Horizontal") * ...