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