[英]How can I change the time that it takes to an animation to run in Unity scripting C#?
I have the player, which is a cube and I want it to "jump" to a chosen empty object position. 我有一个播放器,它是一个立方体,我希望它“跳转”到选定的空对象位置。
I managed to move the player from it's original place with vector3.MoveTowards()
, but at the same time I want to play an animation that shows how the cube jumps to the empty object position. 我设法通过
vector3.MoveTowards()
将播放器从其原始位置vector3.MoveTowards()
,但同时我想播放一个动画,该动画显示多维数据集如何跳至空对象位置。
The problem here is that the empty object position will change so the distance from the cube to the empty object will be different. 这里的问题是空对象的位置将改变,因此从立方体到空对象的距离将不同。 I believe I need to change the time that it takes the animation to complete, so it would pause and after that let the cube move just in a straight line.
我相信我需要更改完成动画所需的时间,因此它将暂停,然后让多维数据集沿直线移动。
I want the animation to take a longer or shorter time to run, given that the empty object position will always change... 考虑到空对象的位置将始终发生变化,我希望动画花费更长或更短的时间来运行...
You can use StartCoroutine in this case. 在这种情况下,您可以使用StartCoroutine。
IEnumerator animated() {
// Code here
yield return new WaitUntil (() => stopanimated == true);
// Run the code here
}
Or you can 或者你可以
IEnumerator animated() {
// Code here
yield return new WaitForSeconds (1); // How much second to wait before execute the next line code.
// Run code here
}
And how to call it use : 以及如何调用它:
StartCoroutine (Animated ()); StartCoroutine(Animated());
For detail documentation coroutine here : 有关详细文档协程,请点击此处:
https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html
This StartCoroutine is use to pause a code for some time before it execute. 该StartCoroutine用于将代码暂停一段时间,然后再执行。
And 和
To change the speed animated : 更改动画速度:
See this post : http://answers.unity3d.com/questions/950205/how-to-change-speed-of-animation-in-c.html 看到这篇文章: http : //answers.unity3d.com/questions/950205/how-to-change-speed-of-animation-in-c.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.