I have a co-routine:
private IEnumerator GameClock()
{
while (isRunning)
{
Debug.Log("Check if paused");
if (!isPaused)
{
currentDate++;
yield return new WaitForSeconds(timescalefactor);
}
else {
Debug.Log("Is Paused");
}
}
}
Like this, it runs perfectly fine. Now however, I’m trying to have a pause button so that the player can pause the game to think etc. I’ve linked a button to a function that flips the isPaused boolean to false, but when that button is clicked, the boolean flips and then Unity hangs/does not respond.
I’ve checked and the boolean-flipping function is working/isn’t causing the system to hang, ie. I can get print statements in that function to print. However, the code doesn’t seem to get to the first ‘Check if Paused’ debug statement (or at least, it doesn’t get printed out before the system hangs) in the enumerator.
Any idea what has happened or how to fix it?