//代码1
IEnumerator A(){
Debug.Log(“hi1”); { yield return new WaitForSeconds(1f); Debug.Log(“hi2”); }Debug.Log(“hi3”);
}
//代码2
IEnumerator A(){
Debug.Log(“hi1”); yield return StartCoroutine (B());Debug.Log(“hi3”);
}
IEnumerator B(){
yield return new WaitForSeconds(1f); Debug.Log(“hi2”);}
代码1和代码2的打印顺序相同,都是hi1 hi2 hi3
但两者并不等价,体现在:
如果我调用StopCoroutine("A"),代码1会全部中止;而代码2只有A被停掉,B不会被停掉。