Animation code not working

here is my code for when i click any where the animation plays:

var hit : AnimationClip;

function Update () {
if (Input.GetMouseButton(0)){
	animation.Play("hit");
	}
}

it say that the animation “hit” could not be found. i have an animator called hit AND an animation called hit. why doesn’t it work?

PS i tried to do a screen shot but i needed 512 kb in size for maximum and i couldn’t.

That’s a sort of unreliable way of going about playing animations, and I can’t offer any advice on sourcing directly from your project other than to define it as a variable (i.e. var : AnimationClip) i.e.:

var walkAnimation : AnimationClip;
 
//And inside update...
animationComp.Play(walkAnimaton.name);

Otherwise, just make it easy on yourself and use the component. You just attach an animation component to the gameObject, throw all of your animations in there, and you can call them much easier and more reliably.

Like this:

if (Input.GetKey (KeyCode.W))
		{
			animation.CrossFade("run");
		}

^ JavaScript