0
我想用我的协程来平滑插入多个GameObjects的位置和旋转,并附上脚本。当我启动协程时,光滑的部分工作正常,但我的所有对象都移动到同一位置,这不是我想要的。我想明白为什么会这样,以及是否有一个聪明的方法来处理它。协程调用堆栈
这是我的协同程序是什么样子:
IEnumerator interpolate_Plate(Transform targ)
{
float passedTime = 0;
while (!transform.Equals(targ))
{
passedTime += Time.deltaTime;
transform.position = Vector3.Lerp(transform.position, targ.position, passedTime);
transform.rotation = Quaternion.Lerp(transform.rotation, targ.rotation,passedTime);
yield return null;
}
yield break;
}
我在想,在它的列表创建mastercoroutine,然后调用平滑部分。 问题只是,Targ的引用总是被重置为堆栈上的所有协程调用?
正如你所需要调用协程的功能:
public void move_Plate(Transform newPosition)
{
StartCoroutine(interpolate_Plate(newPosition));
}
你打算如何调用interpolate_Plate? –
您必须展示如何启动协程。此外,你的最后一次休息是无用的,因为协程在任何时候都会退出。 – Everts
无论如何,您可能不需要协程,在Update中移动逻辑可能足以满足您的需求。 –