How to stop collaboration?

When two joint procedures are performed, how to stop the first joint procedure?

GLOBALS.stableTime = 5;

IEnumerator StableWaittingTime ()
{
        yield return new WaitForSeconds (1f);
        if (GLOBALS.stableTime == 0) {
                GameManager.instance.LevelFaildMethod ();
        } else {
                GameManager.instance.stableWaittingTime.text = GLOBALS.stableTime.ToString ();
                GLOBALS.stableTime--;
                StartCoroutine ("StableWaittingTime");
        }
}
+4
source share
2 answers

@ Imapler's answer is almost all you need. I would just add that the StopCoroutinemethod is MonoBehaviouroverloaded and has 3 types of parameters, so you can stop a lot of coroutines with the same name. For your need, just use the break output here; in the following way:

void Start () 
{
    StartCoroutine (StableWaittingTime ());
}

IEnumerator StableWaittingTime ()
{
    yield return new WaitForSeconds (1f);
    if (false) 
    {
        // do something
    } 
    else 
    {
        // do something
        StartCoroutine (StableWaittingTime ());
        yield break;
    }
}
+1
source

There are three ways to stop coroutines. First you need to call StopAllCoroutines. The second is to call StopCoroutine. And the third is to make a beating from the orphanage.

StopAllCoroutines , StopCoroutine yild. , StopAllCoroutines, StopCoroutine , .

, , , , . , , , , StopCoroutine .

+3

All Articles