Skip to main content
2 of 2
simplified loops
starikcetin
  • 5.3k
  • 4
  • 26
  • 60

Have a boolean flag that indicates if Coroutine Y is running at the instant:

bool isYRunning = false;

IEnumerator Y
{
    isYRunning = true;

    //stuff...

    isYRunning = false;
}

And in X, have something like this:

int waitAmount = 10, waited = 0;

IEnumerator X
{
    //stuff...

    while(waited < waitAmount)
    {
        if(!isYRunning)
        {
            waited += Time.deltaTime;
        }

        yield return null;
    }
    
    waited = 0;
}

Notice that we only increment the waited time if Y is not running.

starikcetin
  • 5.3k
  • 4
  • 26
  • 60