My resume button doesn't work.

I’m trying to change Paused in PCPause to false from TestPause but it doesn’t work. Can somebody try to figure out the problem? Thanks.

PCPause:

using UnityEngine;
using System.Collections;

public class PCPause : MonoBehaviour
{

    public PCPause instance;
    public bool Paused = false;
    public string CurrentMenu;
    public GUIStyle MenuLabelGUIStyle;
    public GUIStyle MenuButtonsGUIStyle;

   
    

    void Update()
    {
        instance = this;

        if (Input.GetKeyDown(KeyCode.Escape)  Paused == false)
        {

            Paused = true;

            GetComponent<MouseLook>().enabled = false;
            GetComponent<FPSInputController>().enabled = false;

        }
        else if (Input.GetKeyDown(KeyCode.Escape)  Paused == true)
        {

            Paused = false;

            GetComponent<MouseLook>().enabled = true;
            GetComponent<FPSInputController>().enabled = true;

        }
    }


}

TestPause:

using UnityEngine;
using System.Collections;

public class TestPause : MonoBehaviour 
{

    public TestPause instance;
    public bool IsPaused = false;
    public string CurrentMenu;
    public GUIStyle MenuLabelGUIStyle;
    public GUIStyle MenuButtonsGUIStyle;
    public PCPause a;

    void Start()
    {
        instance = this;
        CurrentMenu = "PauseMain";
        a = gameObject.GetComponent<PCPause>();
    }

    void OnGUI()
    {
        if (CurrentMenu == "PauseMain")
            Pause_Main();
    }

	void Update() 
    {
        instance = this;

        if (Input.GetKeyDown(KeyCode.Escape)  IsPaused == false)
        {

            IsPaused = true;

            GetComponent<MouseLook>().enabled = false;
            GetComponent<FPSInputController>().enabled = false;

        }
        else if (Input.GetKeyDown(KeyCode.Escape)  IsPaused == true)
        {

            IsPaused = false;
            a.Paused = false;
            GetComponent<MouseLook>().enabled = true;
            GetComponent<FPSInputController>().enabled = true;
     
        }
	}

    public void NavigateTo(string nextmenu)
    {
        CurrentMenu = nextmenu;
    }

    private void Pause_Main()
    {
        if (IsPaused == true)
        {
            GUI.Box(new Rect(10, 10, 200, 50), "Game Paused", MenuLabelGUIStyle);

            if (GUI.Button(new Rect(10, 130, 200, 30), "Disconnect", MenuButtonsGUIStyle))
            {
                Application.LoadLevel("MainMenu");
                Network.Disconnect();
            }

            if (GUI.Button(new Rect(10, 70, 200, 30), "Resume", MenuButtonsGUIStyle))
            {
                IsPaused = false;
                Time.timeScale = 1;
                
            }

            GUI.Box(new Rect(0, 0, 400, Screen.height), "");
        }
    }
}

I notice that you don’t set the a.Pause to true in the TestPause class you only set it to false. Did you mean to pause and unpause it in both cases or are you looking for unpause only from TestPause.

You have the same code ( for handling Escape key ) in both classes, so both are executing it. So TestPause may set a.Paused to false, but then PcPause sets it to true ( as it’s already false - change by second script)

Have you considered using Time to pause your game instead of having a bool that manages it.

You can use

        if (Input.GetKeyDown(KeyCode.Escape))
        {
                if (Time.timeScale == 1f
                    Time.timeScale = 0f;
                }
                else
                {
                    Time.timeScale = 1f;
                }
        }

See the following URL for more information about timeScale.

Once snag is you cant use Input.GetAxis after this since the Axis code appear to be effected by the change. (That was my experience I don’t have specific docs to back that up)

This is because GetAxis is smoothed, which uses the game time rate.

You can use GetAxisRaw to work around this. (in most cases you can switch GetAxis for GetAxisRaw and it will work)