How to play entire animation?

hi guys how can i play entire animation when i hit an object or just simply pushing a button.

here is my script for animation when i hit the object but when i stop moving forward the animation also stops:

function OnControllerColliderHit(hit : ControllerColliderHit) { if (hit.gameObject.tag =="w")//object tag { animation.Play("sit"); } }

please help me. thanks.

I think it stops playing because when you stop colliding...You stop the actual command to play the animation

For a button press

if(Input.GetButton("blah")){ do something;


if(Input.GetKey("a")){ do something;


After looking at your code again, maybe try

function OnControllerColliderHit(hit : ControllerColliderHit) { 

var player = GameObject.FindWithTag("w");

 if (hit.gameObject.tag =="w"){