MonoBehaviour.StopCoroutine

MonoBehaviour.StopCoroutine

Description

Stops all coroutines named methodName running on this behaviour.

Please note that only StartCoroutine using a string method name can be stopped using StopCoroutine

 

自己试验了一下,发现参数需要一一对应

 1 public class MyTest2 : MonoBehaviour
 2 {
 3     IEnumerator curTask;
 4     void OnGUI()
 5     {
 6         if (GUI.Button(new Rect(10, 10, 150, 100), "start")) {
 7             curTask = DealWithForward();
 8             //Please note that only StartCoroutine using IEnumerator 
 9             //can be stopped using StopCoroutine using IEnumerator.
10             StartCoroutine(curTask);
11 
12             //Please note that only StartCoroutine using a string method name 
13             //can be stopped using StopCoroutine using a string method name .
14             //StartCoroutine("DealWithForward");
15         }
16             
17         if (GUI.Button(new Rect(10, 110, 150, 100), "stop"))
18             SotpAnimation();
19     }
20     
21 
22 
23     public IEnumerator DealWithForward()
24     {
25         while (true)
26         {
27             Debug.Log(" 展示 问题 需要 土拨鼠 动画  Time.realtimeSinceStartup :" + Time.realtimeSinceStartup);
28             
29             yield return new WaitForSeconds(3.0f);
30         }
31     }
32 
33     public void SotpAnimation()
34     {
35         Debug.Log("如果 当前 有 土拨鼠 动画 停止");
36 
37         StopCoroutine(curTask);
38 
39         //StopCoroutine("DealWithForward");
40     }
41 }

 

 

 
 

转载于:https://www.cnblogs.com/chongxin/p/4126162.html

你可能感兴趣的:(MonoBehaviour.StopCoroutine)