Hello, I’m creating a program that has to wait until something is true while letting the main program run. I basically want him to stay inside the coroutine until some two values are not equal to each other and not continue in the function that called this coroutine.
private void Update()
{
if (Route.ActiveRoute() && isOnTheMove)
{
StartCoroutine(OnTheMove());
}
}
private IEnumerator OnTheMove()
{
isOnTheMove = false;
//
// Movement code to implement
//
StartCoroutine(timeManager.WaitOneDay());
Debug.Log("One day has passed");
isOnTheMove = true;
yield return null;
}
And this is the coroutine that should wait until some values are not equal.
public IEnumerator WaitOneDay()
{
var currentDay = mainDate.D;
while (true)
{
if(currentDay == mainDate.D)
{
yield break;
}
yield return new WaitForEndOfFrame();
}
}
This coroutine is part of time manager that controls the “mainDate” and adds one day to it once every 2 seconds down to 0.125 seconds (based on what player sets as time speed)… What I want to do is to basically wait until timeManager add one day to the mainDate. But what it currently does is that it will enter the coroutine, then immediately exit and tells me “One day has passed” about 100 times a second… What am I doing wrong here?