calling animation from other script HELP!!!

Hi all,

I’m having some difficulty understanding how to call an animation on an object that doesn’t have the script attached to it.

This is what i have:

  • an animated character called ‘theCharacter’

  • 2 animation cycles, once called ‘idle’ and the other ‘stretch’

  • A script attached to the camera

I have this in the script but can’t seem to get it to initiate. What am i doing wrong?

   var mychar : GameObject;


   function Start () {
    
      mychar = GameObject.Find("theCharacter");          
      mychar.animation.CrossFade ("stretch");    

}

You need to get a reference to the Animation component from your theCharacter.

function Start () {
    mychar = GameObject.Find("theCharacter");          
    mychar.GetComponent(Animation).CrossFade("stretch");    
}

Hi,
taking a reference of the Animation component form Your theCharacter in hierarchy and then attache to Main Camera.

private var mychar : GameObject;

function Start ()
{

mychar = GameObject.Find("theCharacter");

mychar.GetComponent(Animation);

mychar.animation.CrossFade("stretch");

}

Thanks
Ram