Unity 4.x:如何在机械动画中访问动画状态



我在Unity 4.5.x中使用Mecanim动画系统。我在GameObject上有一个名为"VictorSprite"的Animator组件,它有几个层,每个层都有几个动画状态。

如何访问每个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 中使用

p.s.我也试过这个代码,但它没有提供好的功能:

AnimatorStateInfo animState = GameObject.Find("VictorSprite").GetComponent<Animator>().GetCurrentAnimatorStateInfo(2);

p.s.2:基本上,我在一个游戏对象上应用不同层的多个动画,我希望能够动态地暂停其中一个。将其权重设置为0没有帮助,因为它会"重置"动画,而不是暂停。

为了加快速度,

    var animator = unityChan.GetComponent<Animator> ();
    animator.speed = 10.0f;

这应该能满足您的需求。

Animator animator = GameObject.Find("ObjectInScene").GetComponent<Animator>();
AnimationInfo[] stateInfo = animator.GetCurrentAnimationClipState(index);

然而,现在还不清楚你为什么真的想要这个。

最新更新