how to call animation from script

Hi,
i have imported a model from 3Dstudio, and i splitted animation in 3 sub-animations.
When i import the model into hierarchy, the model has attached an Animator Component where i can only insert an animation controller. I also insert an Animation Component, but I cannot understand how to call single animation from a javascript.
Can someone help me?

* http://docs.unity3d.com/Documentation/Manual/Animations40.html * http://docs.unity3d.com/Documentation/Manual/MecanimAnimationSystem.html * http://docs.unity3d.com/Documentation/Components/FBXImporter-Animations.html * http://docs.unity3d.com/Documentation/Components/comp-AnimationGroup.html * http://docs.unity3d.com/Documentation/Components/AnimationEditorGuide.html * http://docs.unity3d.com/Documentation/ScriptReference/Animation.html * http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=Animation

–

2 Answers

2

var clip : AnimationClip;

function Start(){
     animation.Play(clip.name);
}

i tried, and my script now is: var clip : AnimationClip; function Start(){ animation.Play(clip.fight); } but i have this error: 'fight' is not a member of 'UnityEngine.AnimationClip'. In animation component i have walk and fight animation, but it seems that the script doesn't see the animations...

–

you need to provide the name of the clip you want to play so just write clip.name as the argument of animation.Play

–

you need to provide the name of the clip you want to play so just write clip.name as the argument of animation.Play Don't replace name with name of your clip it is "clip.name" where "name" is the member of "AnimationClip"

–

now i tried: animation.Play("fight"); but i have this error: The animation state fight could not be played because it couldn't be found! Please attach an animation clip with the name 'fight' or call this function only for existing animations.

–

i assigned the animation clip as variable in the inspector of the script attached to my model, but i still have an error: The animation state fight could not be played because it couldn't be found! Please attach an animation clip with the name 'fight' or call this function only for existing animations. Could be the problem that my animation clip is inside the model?I really don't understand...

–

Either this:

var clip : AnimationClip;
 
function Start(){
   animation.Play(clip);
}

or this:

function Start() {
   animation.Play("Attack");
}

But for the second to work, you should attach Animation component to the object this script it attached to; and you need to have a clip named “Attack” included in the Animation component.