1、定时循环
void Start ()
{
StartCoroutine("DoSomething");
}
void DoSomething ()
{
while (true)
{
//需要重复执行的代码就放于在此处
print("DoSomething Loop");
//设置间隔时间为10秒
yield WaitForSeconds (10);
}
}
本文介绍如何在Unity中使用C#协程来创建一个无限循环的任务,该任务每10秒执行一次,适合用于游戏开发中的定时任务调度。
1、定时循环
void Start ()
{
StartCoroutine("DoSomething");
}
void DoSomething ()
{
while (true)
{
//需要重复执行的代码就放于在此处
print("DoSomething Loop");
//设置间隔时间为10秒
yield WaitForSeconds (10);
}
}
被折叠的 条评论
为什么被折叠?