unity学习笔记-延迟执行方法

一、计时器

timer += Time.deltaTime;
if (timer > 0.2f)
{
    fangfa();
}

二、Invoke


Invoke("方法名",1f);
Invoke("方法名",几秒后执行);
Invoke("方法名",1f,5f);
Invoke("方法名",1f,每次执行的间隔时长);

三、协程

函数WaitForSeconds
    void Start()
    {
        //启动我们在下面定义的名为ExampleCoroutine的协程。
        StartCoroutine(ExampleCoroutine());
    }
 
    IEnumerator ExampleCoroutine()
    {
        //打印函数第一次调用的时间。
        Debug.Log("Started Coroutine at timestamp : " + Time.time);
 
        //生成一个等待5秒的yield指令。
        yield return new WaitForSeconds(5);
 
        //等待5秒后再次打印时间。
        Debug.Log("Finished Coroutine at timestamp : " + Time.time);
    }
-------------------------------------------------------------------------
函数WaitForSecondsRealtime

    void Start()
    {
        StartCoroutine(Example());
    }
 
    IEnumerator Example()
    {
        print(Time.time);
        yield return new WaitForSecondsRealtime(5);
        print(Time.time);
    }
--------------------------------------------------------------------

四、DoTween

我辣鸡,不会用

扫描二维码关注公众号,回复: 16891642 查看本文章

猜你喜欢

转载自blog.csdn.net/m0_73841296/article/details/131471743