How to access Animation using java script & attach it to the object ?

i have created the walking & idle animation for my fps player. i’ve added a java_script to access it. but, when i run it & press button(w), it stops & says that, the animation is not attached to the object… when i drag the walking/idle animation & drop to that object, it creates an animation controller. again i run it, still same error. i can’t find where to attach the animation ??? thnx for help… @Adamcbrz @Olgo @whydoidoit @VildNinja @hollym16 @ Here’s my java script:

function Update ()
{

	if(Input.GetKeyDown("w"))
	{
		GetComponent.<Animation>().Play("walk_anim2", PlayMode.StopAll);
	}
	if(Input.GetKeyUp("w"))
	{
		GetComponent.<Animation>().Play("idle_anim2", PlayMode.StopAll);
	}

}

first, it is GetComponent(Animator)

second, it works like a state machine with transitions where you define the conditions in those white arrows. In your case this would be a speed float value higher than 0 for entering walking and 0 for going back to idle. the animator uses SetFloat for this.

see the docs for a description of the Animator about how to use this and read this carefully to get an understanding how everything works