problem with timeScale = 0 (game paused)
Hi all, I'm trying to pause the game using timeScale and fortunatly everything is working fine except one thing! When the game is paused and i click on the screen the player and the whole game make little movement. So if I click several time on the screen the game ignore the timescale. Also, when i click on the button to restart/resume the game, it will generate another little movement before to set timescale = 1 again
Here you can find my code:
// Update is called once per frame
void Update () {
if (isPaused && !counter.activeInHierarchy)
{
pauseMenuCanvas.SetActive(true);
Time.timeScale = 0;
}
else if (counter.activeInHierarchy)
{
pauseMenuCanvas.SetActive(false);
//Time.timeScale = 1;
}
else
{
Time.timeScale = 1;
pauseMenuCanvas.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.Escape))
pauseGame();
}
public void pauseGame()
{
isPaused = !isPaused;
}
public static class CoroutineUtil
{
public static IEnumerator WaitForRealSeconds(float time)
{
float start = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup < start + time)
{
yield return null;
}
}
}
public void Resume()
{
pauseMenuCanvas.SetActive(false);
StartCoroutine(MyCoroutine());
}
private IEnumerator MyCoroutine()
{
counter.SetActive(true);
yield return StartCoroutine(CoroutineUtil.WaitForRealSeconds(3));
counter.SetActive(false);
isPaused = false;
Time.timeScale = 1;
}
public void reloadGame()
{
SceneManager.LoadScene("Play");
}
}
Thanks in advance
Your answer
Follow this Question
Related Questions
How to Pause Menu with Animating Button Works? 1 Answer
How do i stop my mouse from being in first person when a pause menu appears? 0 Answers
How can I make sure that the game is selected after closing out of a pause menu? 0 Answers
Is UI affected by time scale ? 1 Answer
I need to click after unpausing game to hide the cursor 0 Answers