今天想要停止一個協成,發現調用?StopCoroutine(ShowDebug()); 竟然不管用,后來看了文檔才知道,原來想要停止協成,必須用字符啟動協程?StartCoroutine("ShowDebug");?
然后再調用?? ? ? ? StopCoroutine("ShowDebug"); ?
IEnumerator ShowDebug()
{
Debug.LogError("執行一次1");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次2");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次3");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次4");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次5");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次6");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次7");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次8");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次9");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次10");
yield return new WaitForSeconds(1f);
Debug.LogError("執行一次11");
yield return new WaitForSeconds(1f);
}
?
如果不用字符串的話,會發現,他一直在打印,如果用了字符串就會發現,成功停止了
?