Pause and Unpause game with one bool

Hello everyone.

I am trying to pause and un-pause my game with one boolean variable but it is not working. like this, I have a bank building that when I click on it, causes game to pause and in ui I have a back button, that when player clicks on it, it should un-pause the game but either of codes work separately than the other. I really can use some help here.

public class PauseSc : MonoBehaviour {

public static PauseSc pauseTheGame;

public bool isPaused = false;
// Use this for initialization
void Start () {
	
}

// Update is called once per frame
void Update () {
	
}

public void ClickToPause()
{
	isPaused=!isPaused;
	Debug.Log("Button pause : "+isPaused);
    Time.timeScale = isPaused ? 0 : 1;
}

void OnMouseDown()
{
	isPaused=!isPaused;
	Debug.Log("Building pause func : "+isPaused);
    Time.timeScale = isPaused ? 0 : 1;
}

}

Shouldn’t the Time.timeScale = isPaused ? 0 : 1; be in Update or something, rather than in one or an other clickEvent ?

I think OnMouseDown isn’t usefull, you should be able to do it in only one method.

 public void ClickToPause()
 {
if (isPaused)
     isPaused = false;
else if (!isPaused)
isPause = true;
     Debug.Log("Button pause : "+isPaused);
     Time.timeScale = isPaused ? 0 : 1;
 }

if it was me I would take the time.timescale in an other method I would call from here, but, well, why not.

Have a nice day !

Could you describe exactly the problem you are encountering?

@nXFiles

If it’s still actual, you can do like this:

Step 1 - Create GameManager and assign GameManagerScript to it
Step 2 - Make child object PauseManager and assign PauseScript to it
Step 3 - Select how to call 2 different methods in GameManagerScript - it could be butons, etc.

PauseScript

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseScript : MonoBehaviour
{
    public bool gameIsPaused = false;


    void Update()
    {
        if (gameIsPaused == true)
        {

            PauseGame();
            
        }
    }
    void PauseGame()
    {
        //Start Count Down
        //Show Menu

        if (gameIsPaused)
        {
            Time.timeScale = 0f;
        }

    }

    public void Debugger()
    {
        Debug.Log(gameIsPaused);
    }
}

GameManagerScript (part of it)

//
//
//
//
    void Start()
    {
        PauseScriptScript = PauseManager.GetComponent<PauseScript>();
    } 
//
//
//
//
//
    public void GamePause()
    {
        PauseScriptScript.gameIsPaused = true;


    }

    public void ContinueTheGame()
    {
        Time.timeScale = 1;
        PauseScriptScript.gameIsPaused = false;
        PauseScriptScript.Debugger();
    }
//
//
//