Unity3d Coroutine的Start和Stop

StopCoroutine的几种方法:

  1. StopCoroutine(string method):

    StartCoroutine("Test");
    StopCoroutine("Test");
    
    StartCoroutine("Test2",1);
    StopCoroutine("Test2");
    
  2. StopCoroutine(Coroutine routine)

    以下这样调用停不掉Coroutine
    StartCoroutine(Test());
    StopCoroutine(Test());
    StartCoroutine(Test2(1));
    StopCoroutine(Test2(1));
    应该这样
    Coroutine c = StartCoroutine(Test3(p1,p2));
    StopCoroutine(c)

  3. StopCoroutine(IEnumrator routine)

    IEnumrator coroutine = Test();
    StartCoroutine(coroutine );
    StopCoroutine(coroutine);
    
    IEnumrator coroutine1 = Test2(1);
    StartCoroutine(coroutine1  );
    StopCoroutine(coroutine1 );
    

    以下这样调用停不掉Coroutine:

    IEnumrator coroutine1 = Test();
    IEnumrator coroutine2 = Test();
    StartCoroutine(coroutine1 );
    StopCoroutine(coroutine2 );
    
  4. StopAllCoroutines()
    可以停掉当前脚本的所有Coroutine.

你可能感兴趣的:(Unity挖掘机)