【发布时间】:2014-12-29 11:13:35
【问题描述】:
我在 Unity 4.5.x 中使用 Mecanim 动画系统。我在一个名为“VictorSprite”的 GameObject 上有一个 Animator 组件,它有几个图层,每个图层都有几个 AnimationState。
如何访问每个 AnimationState 以更改其属性,特别是速度?
不幸的是,我能找到的大多数文档都已弃用,并且没有提到 Mecanim。我也试过这段代码:
AnimationState animState = GameObject.Find("VictorSprite").GetComponent<Animator>().animation["VictorTalk"];
但是,我收到此错误消息:
"MissingComponentException: There is no 'Animation' attached to the "VictorSprite" game object, but a script is trying to access it. You probably need to add a Animation to the game object "VictorSprite". Or your script needs to check if the component is attached before using it."
Unity 3.x 动画组件已弃用,在 Unity 4.x 中不再推荐使用。
附言我也试过这段代码,但它没有提供好的功能:
AnimatorStateInfo animState = GameObject.Find("VictorSprite").GetComponent<Animator>().GetCurrentAnimatorStateInfo(2);
附言2:基本上,我在游戏对象的不同层中应用多个动画,并且我希望能够动态地暂停其中一个。将其权重设置为 0 没有帮助,因为它会“重置”动画,而不是暂停。
【问题讨论】: