Question by
GuardianWorld · May 07, 2017 at 12:25 AM ·
unity564-bit
Making a function wait in a Pause Menu
I'm having a little problem in my Main Menu Script, It uses a Canvas and a Disable function, but i have a little bug that one of my scripts inside the Canvas can't run if i unpause the game, because it disables the UI too quickly, where/how i do a wait function to make the game unpause after 0.5 seconds?
public GameObject pauseMenu;
public Transform Player;
public bool isPaused;
// Use this for initialization
void Start ()
{
isPaused = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = (false);
}
// Update is called once per frame
void Update ()
{
if (isPaused) {
PauseGame(true);
}
else
{
PauseGame(false);
}
if (Input.GetButtonDown("Cancel"))
{
SwitchPause();
}
}
void PauseGame(bool state)
{
if(state)
{
Time.timeScale = 0.0f; //Paused
Player.GetComponent<FirstPersonController>().enabled = false;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
} else {
Time.timeScale = 1.0f; //Nope Paused
Cursor.visible = false;
Player.GetComponent<FirstPersonController>().enabled = true;
Cursor.lockState = CursorLockMode.Locked;
}
pauseMenu.SetActive(state);
}
public void SwitchPause()
{
if (isPaused)
{
isPaused = false; //Changes the Value of isPaused
}
else
{
isPaused = true; //Same
}
}
}
Comment