Unity 定時器與延時函數使用


定時器:

單觸發定時器:Invoke(string method,int Secondtimes) 過Secondtimes 秒后觸發method 函數,

重復觸發InvokeRepeating(string method,int Secondtimetowake,int Secondtimetonext)每Secondtimetonext觸發下一次

定義事件

//定義事件
void
DestoryText(){ Destroy(GameObject.Find("text_prefab(Clone)")); }

在需要的地方開啟定時器

Invoke ("DestoryText", 1);

或者

InvokeRepeating("DestoryText",1,1);

*******************************************************************************************************************************************************************

*******************************************************************************************************************************************************************

Unity 使用延時函數,將想要使用延時的函數定義為IEnumerator 類型,然后使用StartCoroutine(IEnumerator routine)調用該函數

    IEnumerator CreateAllChip(){
        for (int i = 0; i < prefab_chip.Length; i++) {
            Instantiate (prefab_chip [i]);
            print (i);
            yield return new WaitForSeconds(2);     //只用函數類型為IEnumerator才能使用該語句,延遲兩秒
        }

    }

在需要的地方

StartCoroutine (CreateAllChip ());

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM