[英]Waiting in Unity 3D game engine in C#?
Is there a command in Unity 3D game engine with C# to make the code wait before something happens? 使用C#的Unity 3D游戏引擎中是否存在命令,以使代码在发生某些事情之前等待? Here is an example: 这是一个例子:
void Start () {
//(wait code here)
Connect();
}
The promoted way of doing this with the Unity3D Game Engine tutorials is with WaitForSeconds
which waits for a given float value (such as 0.5f for half a second). 使用Unity3D游戏引擎教程进行此升级的方法是使用WaitForSeconds
,它等待一个给定的浮点值(例如0.5f持续半秒钟)。
But with this rule you need to set the class to an IEnumerator
so: 但是使用此规则,您需要将类设置为IEnumerator
这样:
public flat StartWait;
IEnumerator SpawnWaves ()
{
//your code
yield return new WaitForSeconds (StartWait);
}
This causes the class/object to wait without freezing the whole game logic. 这将导致类/对象等待而不冻结整个游戏逻辑。 See also http://unity3d.com/learn/tutorials/projects/space-shooter/spawning-waves 另请参见http://unity3d.com/learn/tutorials/projects/space-shooter/spawning-waves
http://docs.unity3d.com/ScriptReference/WaitForSeconds.html http://docs.unity3d.com/ScriptReference/WaitForSeconds.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.