0
votes

I'm using Mecanim Animation System in Unity 4.5.x. I have an Animator component on a GameObject called "VictorSprite", with several layers, each layer has several AnimationStates.

How can I access each AnimationState to change its properties, specifically speed?

Unfortunately, most of the documents I can find are deprecated, and don't refer to Mecanim. I have also tried this code:

AnimationState animState = GameObject.Find("VictorSprite").GetComponent<Animator>().animation["VictorTalk"]; 

But, I receive this error message:

"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 Animation component is deprecated and is not recommended anymore in Unity 4.x.

p.s. I tried this code too, but it doesn't provide good functionality:

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

p.s. 2: Basically, I'm applying multiple animations in different layers on a game object, and I want to be able to pause one of them dynamically. Setting its weight to 0 is not helpful, because it "resets" the animation, instead of pausing.

2

2 Answers

1
votes

To speed up,

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

This should give you what you want.

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

However, it is a bit unclear why you would actually want this.