MonoBehaviour.StopCoroutine

时间:2023-03-09 05:03:07
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

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

 public class MyTest2 : MonoBehaviour
{
IEnumerator curTask;
void OnGUI()
{
if (GUI.Button(new Rect(, , , ), "start")) {
curTask = DealWithForward();
//Please note that only StartCoroutine using IEnumerator
//can be stopped using StopCoroutine using IEnumerator.
StartCoroutine(curTask); //Please note that only StartCoroutine using a string method name
//can be stopped using StopCoroutine using a string method name .
//StartCoroutine("DealWithForward");
} if (GUI.Button(new Rect(, , , ), "stop"))
SotpAnimation();
} public IEnumerator DealWithForward()
{
while (true)
{
Debug.Log(" 展示 问题 需要 土拨鼠 动画 Time.realtimeSinceStartup :" + Time.realtimeSinceStartup); yield return new WaitForSeconds(3.0f);
}
} public void SotpAnimation()
{
Debug.Log("如果 当前 有 土拨鼠 动画 停止"); StopCoroutine(curTask); //StopCoroutine("DealWithForward");
}
}