How to switch between animations imported from Maya?

How to switch between animations if I animated my objects in Autodesk Maya and imported them into Unity? The default animation is running correctly, however Im not sure what should I do if I want to change it to another set of animation through scripting. Any kind help would be greatly appreciated!

By default, my game object is already playing the "walking" animation. What should I do if I want to change the "walking" animation to the "jumping" animation through editing the script? All animations are done in Autodesk Maya

1 Answer

1

Hi,
Considering that you have either:
A) Split a big animation into several smaller or

B) have imported the animations via different fbx by using basemodel@animationName per the unity manual…

…you should have an animation component on your gameObject that holds a list of all those animations.

From a script attached to the same gameObject you can simply call:

var cfadeTime:float;
animation.CrossFade("animationName", cFadeTime);

or

animation.Play("animationName");

animation is a monobehaviour variable which gets the Animation Component attached to the gameObject for you.

Hi, does that mean that if I want to switch the animation via scripting, I can just call animation.Play("animationName"); and the animation will be changed?

Yes thats the simpleset way of changing/playing an animation that exists in the Animation Component.