2017-03-16 64 views
0

我有玩家,这是一个立方体,我想让它“跳”到选定的空物体位置。如何更改动画在Unity脚本C#中运行所需的时间?

我设法从vector3.MoveTowards()的原始位置移动玩家,但同时我想播放一个动画,显示立方体如何跳到空的物体位置。

这里的问题是空对象的位置会改变,所以从立方体到空对象的距离将会不同。我相信我需要改变动画完成的时间,所以它会暂停,然后让立方体直线移动。

我希望动画需要较长或较短的时间来运行,考虑到空对象位置会改变的,...

+0

看到这个职位https://docs.unity3d.com/ScriptReference/AnimationState-speed.html –

+0

如果您使用Animator:https://docs.unity3d.com/ScriptReference/Animator-speed.html –

回答

0

您可以在此情况下,使用StartCoroutine。

IEnumerator animated() { 
     // Code here 
     yield return new WaitUntil (() => stopanimated == true); 
     // Run the code here 
} 

或者你可以

IEnumerator animated() { 
     // Code here 
     yield return new WaitForSeconds (1); // How much second to wait before execute the next line code. 
     // Run code here 
} 

以及如何调用它使用:

StartCoroutine(动画());

因为在这里详细的文档协同程序:

https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html

这StartCoroutine是使用暂停代码一段时间它执行之前。

而且

要更改动画的速度:如果你使用动画 http://answers.unity3d.com/questions/950205/how-to-change-speed-of-animation-in-c.html

+0

谢谢!有效! –