unity,下面两个协程不等价

//代码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不会被停掉。

posted on 2016-05-29 13:40  wantnon  阅读(433)  评论(0编辑  收藏  举报

导航