【发布时间】:2012-02-01 05:30:59
【问题描述】:
我必须延迟这个过程的发生,我在 Update 函数中调用它。 我也尝试过 CoUpdate 解决方法。这是我的代码:-
function Start()
{
StartCoroutine("CoStart");
}
function CoStart() : IEnumerator
{
while(true)
{
yield CoUpdate();
}
}
function CoUpdate()
{
//I have placed the code of the Update().
//And called the wait function wherever needed.
}
function wait()
{
checkOnce=1; //Whenever the character is moved.
yield WaitForSeconds(2); //Delay of 2 seconds.
}
当第三人称控制器(即另一个对象)移出边界时,我必须移动一个对象。我在我的代码中包含了“yield”。但是,发生的问题是:当我在 Update() 中给出代码时正在移动的对象正在移动,但没有停止。它正在上下移动。我不知道发生了什么!有人可以帮忙吗?请,谢谢。
【问题讨论】:
-
您应该添加一些关于对象如何移动的信息。到目前为止,我看不出协程的使用与您的对象移动之间的关系。而且,顺便说一句,我认为这不是解决您的问题的正确方法,看看它有多复杂。
-
使用 IEnumerator 函数,你可以通过 yield WaitForSeconds(n) 来延迟。
标签: unity3d unityscript