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;
}
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);
}
}