【问题标题】:Unity 4.x: How to Access AnimationState in MecanimUnity 4.x:如何在 Mecanim 中访问 AnimationState
【发布时间】: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 没有帮助,因为它会“重置”动画,而不是暂停。

【问题讨论】:

    标签: c# animation unity3d


    【解决方案1】:

    为了加快速度,

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

    【讨论】:

      【解决方案2】:

      这应该给你你想要的。

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

      但是,您实际上为什么想要这个有点不清楚。

      【讨论】:

      • 感谢您的快速回复,但不幸的是它没有帮助。 AnimationInfo 类没有我可以设置为 0 的“速度”字段。
      • 故事是这样的,我有一个 2D 精灵,有时会同时对对象应用 2 个动画。一个改变比例,另一个使它反弹。我希望能够根据游戏的逻辑暂停其中一个。
      • 简单地说,就是如何在具有多个附加层的 Animator 中暂停正在播放的动画状态。
      猜你喜欢
      • 2013-04-16
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多