I'm expecting the program to pause until yield is executed but it's not. The DisplayTileBacks() function runs while PauseGame() is being executed:
void Start()
{
...
DisplayTileFronts();
StartCoroutine(PauseGame(3f));
DisplayTileBacks();
}
public IEnumerator PauseGame(float waitTime)
{
Time.timeScale = 0f;
float waitEndTime = Time.realtimeSinceStartup waitTime;
while (Time.realtimeSinceStartup < waitEndTime)
{
yield return 0;
}
Time.timeScale = 1f;
}
What am I doing wrong?
CodePudding user response:
You need to edit code similar to the following.
void Start()
{
...
StartCoroutine(Display(3f));
}
public IEnumerator Display(float waitTime)
{
DisplayTileFronts();
yield return new WaitForSeconds(waitTime));
DisplayTileBacks();
}