定時器:
單觸發定時器: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 ());