Problem with finding animator.

So i have a weapon that gets Instantiated into the scene and it need a animator. I tried to use this code but it wouldn’t work.

var TheAnimator : Animator;
function Awake ()
{
	var TheAnimator : Animator = gameObject.GetComponent("Animator") as Animator;
}

I need to the script to find it automatically or I wont be able to make it work.

You’ve already declared TheAnimator at the top of your class - so don’t redeclare it as a local variable within Awake() as well. Also, I’d recommend you always use the generic version of GetComponent to avoid the need for casting.

var TheAnimator : Animator;
function Awake ()
{
   TheAnimator = GetComponent.<Animator>();
}

Alternatively, is there a reason why you don’t just drag the Animator component into the TheAnimator slot in the inspector?