Hi there. I wanted to use a Coroutine to make my game pause for a couple seconds whilst the players state changes (eg. Small or big player like in Super Mario).
Everything looks fine to me after studying the docs, but the code after the coroutine which I wanted to use to unpause the game never gets called and the game stays paused:
void SwitchPowerStates(PowerState newState)
{
currentPowerState = newState;
switch (currentPowerState)
{
case PowerState.SMALL:
{
// code that changes the size
break;
}
case PowerState.BIG:
{
// code that changes the size
break;
}
}
StartCoroutine(PauseAndWaitFiveSecs(2f));
Debug.Log("this gets called before the coroutine is started");
}
void PauseGame()
{
Time.timeScale = 0f;
}
void UnPauseGame()
{
Time.timeScale = 1f;
}
IEnumerator PauseAndWaitFiveSecs(float waitTime)
{
PauseGame();
Debug.Log("before time = " + Time.time);
yield return new WaitForSeconds(waitTime);
// WHY IS NONE OF THE FOLLOWING CODE CALLED???
Debug.Log("after time = " + Time.time); // doesnt happen?
UnPauseGame(); // doesnt happen?
}
I commented the area of code where I expected to be able to unpause the game. I think i included all the relevant code.
Really hope someone can help me.
Thanks