这是一个初学者问题,应该可以从第一个google结果中找到,但我找不到它。
我有一个使用Animator播放动画的方法
IEnumerator popDownAnimation(string c)
{
animator = GetComponent<Animator>();
animator.Play("Pop Down Animation");
yield return new WaitUntil(() => animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !animator.IsInTransition(0));
animator.Play("New State");
}不记得从哪弄来的了,但yield return new WaitUntil(() => animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !animator.IsInTransition(0));不工作了。它立即从"Pop Down Animation“跳到"New State",所以"Pop Down Animation”没有机会播放。
发布于 2021-11-12 03:52:10
尝尝这个
IEnumerator popDownAnimation(string c)
{
animator = GetComponent<Animator>();
animator.Play("Pop Down Animation");
float animationLength = animator.GetCurrentAnimatorStateInfo(0).length;
yield return new WaitForSecondsRealtime(animationLength);
animator.Play("New State");
}然而,就像@NotVeryGoodAtThis提到的那样,我不会在代码中这样做,除非你有一个特定的原因,为什么你不能使用动画事件或使用动画生成器中的参数在动画状态之间转换。使用Unity的Animator窗口设计动画并使用状态、参数和过渡将比通过代码更容易管理,特别是在动画制作人员变得更加复杂的情况下。
发布于 2021-11-11 18:08:28
我建议使用动画事件来做你需要做的任何事情。只需记住创建一个公共方法并将动画事件添加到动画的末尾即可。
https://stackoverflow.com/questions/69932054
复制相似问题