Unity 3d 里有关时间延迟
来源:互联网 发布:英语单词读音软件初中 编辑:程序博客网 时间:2024/04/28 20:34
IEnumerator WaitAndPrint(float waitTime)
{
// pause execution for waitTime seconds
yield return new WaitForSeconds(waitTime);
print("----------------")
}
在其它方法里调用:
StartCoroutine(WaitAndPrint(3.0F));
好像在Update里不好用。或者说不能使用。求解ing。。。。。。。
暂停Time.timeScale = 0;
FixedUpdate功能将不会被调用时, 时间刻度设置为零。
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Coroutines & Yield ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
在编写游戏代码的时候,常常需要处理一系列事件。如:
Private Update()
{
if(state == 0)
{
state = 1;
return;
}
if(state == 1)
{
state = 2;
return;
}
}
更方便的是使用yield语句。yield语句是一个特殊类型的返回,他确保在下次调用时该函数继续从该yield语句之后执行。
while(true)
{
// 做步骤1
yield; // 等待一帧
// 做步骤2
yield; // 等待一帧
}
你也可以传递特定的值给yield语句来延迟Update函数的执行,直到一个特定的事件发生。
// 做一些事儿
yield WaitForSeconds(5.0); // 等待5秒
// 做其他事儿
可以叠加和连接coroutines。
这个例子执行Do,在调用之后立即继续。
Do();
print("this is printed immedinately");
function Do()
{
print("do now");
yield WaitForSeconds(2);
print("Do 2 seconds later");
}
这个例子将执行Doo并等待它完成,再继续执行自己。
yield StartCoroutine("Doo");
print("Also after 2 seconds");
print("This is after the doo coroutine has finished execution");
function Doo()
{
print("Doo now");
yield WaitForSeconds(2);
print("Doo 2 seconds later");
}
任何事件处理句柄都可以是一个coroutine。
注意:不能在Update或FixedUpdate内使用yield。但是你可以使用StartCoroutine来开始一个函数。
- Unity 3d 里有关时间延迟
- [Unity 3D] Unity 3D 里的碰撞检测
- Unity 3D 里的碰撞检测
- unity 3D 里的刚体属性
- [Unity 3D]Unity4里用MonoDevelop调试WebPlayer
- Unity 3D 技能释放的脚本 技能冷却时间
- unity时间延迟方法总结(新人勿喷)
- Unity 3D
- unity 3d 注意事项
- Unity 3d 摄像头
- Unity 3D 使用
- Unity 3D--PlayerPrefs
- Unity 3d
- Unity 3D俄罗斯方块
- unity 3d 多开
- UNITY 3D笔记
- Unity 3D接触
- unity 3d
- Unity3D 如何调用DLL
- hive partition
- Lisp真的是屠龙之技吗?
- C++ 回忆录 friend
- 在我最美好的年华,遇见最深情的你
- Unity 3d 里有关时间延迟
- 2012 Multi-University Training Contest 2 [hdu4310~4319]
- 在MySQL中利用外键实现级联删除!
- Unity 台湾官方论坛
- C#程序实现动态调用DLL的研究
- 报名了公司的“秀秀我的办公桌”活动
- 用Swing定制流动的Link样式
- 数据库学习笔记1
- ubuntu 网卡驱动安装