定时器:
单触发定时器: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 ());