[Unity基础]Unity协程的开启和关闭

本文转自:http://blog.csdn.net/yanhui2012/article/details/46775593,请点击链接查看原文,尊重楼主版权。

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基础)