一、计时器
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
我辣鸡,不会用