Skip to main content
simplified loops
Source Link
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(truewaited < waitAmount)
    {
        if(waited < waitAmount && !isYRunning)
        {
            waited += timeTime.deltaTime;
         }

   yield return null;
      yield return }null;
    }
    
    waited = 0;
}

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

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(true)
    {
        if(waited < waitAmount && !isYRunning)
        {
            waited += time.deltaTime;
            yield return null;
        }
    }
    
    waited = 0;
}

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

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.

Source Link
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(true)
    {
        if(waited < waitAmount && !isYRunning)
        {
            waited += time.deltaTime;
            yield return null;
        }
    }
    
    waited = 0;
}

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