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:

  1. 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 calling rb.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 || ...

Get Unity 2017 Mobile Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.