草庐IT

CustomYieldInstruction

全部标签

【Unity知识点详解】StartCoroutine、CustomYieldInstruction详解

    Unity提供了StartCoroutine方法来启动一个协程方法,协程方法可以通过yield语句将程序挂起,暂停程序执行。在程序恢复执行时继续执行后续的代码。publicclassMain:MonoBehaviour{//StartiscalledbeforethefirstframeupdatevoidStart(){StartCoroutine(Coroutine());}IEnumeratorCoroutine(){Debug.Log("Log111111");yieldreturnnewWaitForSeconds(1f);Debug.Log("Log222222");}}