Unity3d 協程(IEnumerator)範例

using UnityEngine;  
using System.Collections;  
  
public class Test : MonoBehaviour   
{  
    IEnumerator Start ()   
    {  
        yield return StartCoroutine(login());  
          
        Debug.Log("CCCCCCCCCCCCC");  
          
        Destroy(this.gameObject);  
    }  
      
    IEnumerator login ()   
    {  
        Debug.Log("AAAAAAAAAAAAAAAAA");  
          
        yield return new WaitForSeconds(0);  
          
        Debug.Log("BBBBBBBBBBBBBBBBB");  
    }  
}

------print--------
AAAAAAAAAAA
BBBBBBBBBBB
CCCCCCCCCCC
--------------------this

using UnityEngine;  
using System.Collections;  
  
public class Test : MonoBehaviour   
{  
    void Start ()   
    {  
        StartCoroutine(login());  
          
        Debug.Log("CCCCCCCCCCCCC");  
          
        Destroy(this.gameObject);  
    }  
      
    IEnumerator login ()   
    {  
        Debug.Log("AAAAAAAAAAAAAAAAA");  
          
        yield return new WaitForSeconds(0);  
          
        Debug.Log("BBBBBBBBBBBBBBBBB");  
    }  
}

------print--------
AAAAAAAAAAA
CCCCCCCCCCCcode

相關文章
相關標籤/搜索