can someone show me how to play a death animation when a the game object is destroyed (javascript)

Basically i need help with getting my enemy in game to play a death animation when the game object is destroyed.

In your script somewhere you would call Destroy() like so:

// if this script is attached to the object to destroy
animation.Play("animation name goes here");
Destroy(this.gameObject, animation.time);

try this :slight_smile:

#pragma strict

var Health = 100;
var animDie : AnimationClip; // Drag your animation from the project view in here (to inspector)

function ApplyDammage (TheDammage : int)
{
    Health -= TheDammage;
    if(Health <= 0)
    {
       Dead();
    }
}

function Dead()
{
    animation.Play(animDie.name);
    Destroy(this.gameObject, animDie.length);
}

hope it helps

Help me pls script is not work
send me instructions gagac@centrum.sk