When animation is playing, animation is cut.

I make a animation is called “hurt”.
When the boy collides B (the cube), the boy will doing “hurt” animation.
But animation seems like flashing and see unclear.
I think when animation is playing, animation is cut…
Refer to hurt2’s link: http://www.facebook.com/video/video.php?v=226490747366899&saved#!/video/video.php?v=226491344033506

My code:

function OnTriggerStay(other : Collider){
if (other.gameObject.tag == "pass" )  {
animation.Play("hurt");
audio.clip=bump;
audio.Play();
score=score-1;
Destroy (other.gameObject);
}
}

But when I put “name@hurt” animation (setting loop) into scene, hurt animation seem like success.
Refer to hurt1’s link: http://www.facebook.com/video/video.php?v=226490747366899&saved#!/video/video.php?v=226490747366899
Why animation is cut? Because I add “destory” in behind of my code?
What method can let animation success and isn’t cut?
Thanks everybody!

Destroy is removing the gameObject before it has a chance to play the animation.

Destroy (other.gameObject,animation(“hurt”).length); //Should delay the destruction of the gameobject until the animation is finished.

Well, that depends entirely on the rest of your code, really. If your code makes animations play as part of movement or standing around, it’s likely conflicting with this one using Animation.Play().

Also, you’re generally better off with OnCollisionEnter() than OnCollisionStay(), seeing as you’re destroying what you collide with.

First thanks ackyth and GargerathSunman :slight_smile:

Destroy (other.gameObject,animation("hurt").length);

Above code have a error:
It is not possible to invoke an expression of type ‘UnityEngine.AnimationClip’.
I serch network and get correct code:

Destroy (other.gameObject,animation.clip.length);

I put above code into OnCollisionStay() and OnCollisionEnter(), result is different…

OnCollisionStay():
“hurt” animation is success and no break off.
But score accumulate and audio replay until “hurt” animation is over.

OnCollisionEnter():
“hurt” animation is break off.
Audio and score are no error.

But OnCollisionStay and OnCollisionEnter() have same error…
By collision of object (cube) isn’t disappear.
Because add “animation.clip.length” in behind of destory?
I want animation isn’t break off and cube is disappear. Score correct display and audio play once
What can I do…
Thanks again!