how can i make the box to do an animation when it is hitted?

how can i make the box to do an animation when it is hitted by other 3d objects?? :slight_smile:

You can use a collider and turn it to a trigger, then use OnTriggerEnter function. Or you can leave the trigger unchecked and use OnCollisionEnter to call any animations or any thing else like sound or explosion. :smile:

sorry sir… i can’t imagine what you’re saying. Do you have any code examples regarding this question?? :slight_smile:

Look in the script manual under runtime classes/monohehaviour/OnTriggerEnter and then with that function call the animation to play. :smile:

@tunabelly14 - if you run through the tutorials on the Unity website, you will learn all about this stuff.

http://unity3d.com/support/resources/

im using this script

function OnControllerColliderHit (hit : ControllerColliderHit){
animation.CrossFade(“computeranimation”);

}

and i also try some codes that are related to it but, it still doesn’t work… :c

Animation.CrossFade needs to be called every frame in the Update function to work correctly. You can use animation.Play to set an animation running from the OnControllerColliderHit function. Alternatively, you can set an integer variable in OnControllerColliderHit to denote which animation should be running:-

var currAnim: int;
   ...

function OnControllerColliderHit (hit : ControllerColliderHit){
  currAnim = 1;
}

…and then use that in the Update function with CrossFade:-

function Update() {
  if (currAnim == 0) {
    animation.CrossFade("Idle");
  } else if (currAnim == 1) {
    animation.CrossFade("Walk");
  } // etc...
}