[Help Please] Death Animation

I have made it so that when I click it sends a raycast down and deals damage to the object and destroys it when it runs out of health. But then I tried making it so that it plays an animation when it is destroyed. That is where things started to go wrong, when I did this in my coding it made it so that now it no longer destroys the object and hence doesn’t transition to the other animation. Does anyone know what I am doing wrong?
Here is the error I am getting…
ComponentException: There is no ‘Animation’ attached to the “MenuSheep” game object, but a script is trying to access it.
You probably need to add a Animation to the game object “MenuSheep”. Or your script needs to check if the component is attached before using it

Here is my coding…

#pragma strict
var ourObject : GameObject;
var currentHealth : float = 0.0f;
var maximumHealth : float = 15.0f;


function Start () {
    currentHealth = maximumHealth;
    }

function ApplyDamage (bulletDamage : float) {
    currentHealth -= bulletDamage;
    if(currentHealth <= 0) {
            GameObject.Find("MenuSheep").animation.Play("DeathAnimation");
            Destroytimer ();
            }
    }
function Destroytimer (){
    yield WaitForSeconds (animation["DeathAnimation"].length);
    Destroy(ourObject);
    }

Not sure what I am doing wrong :frowning:

You need to add an Animation component to your “MenuSheep” gameObject.

Select it and go to AddComponent > Miscellaneous > Animation.

I have done so but when I do it automatically plays the animation I attach to it instead of waiting for it to be destroyed

Try turning off “Play Automatically” on your Animation component.

I am now getting the error…
The animation state DeathAnimation could not be played because it couldn’t be found!
Please attach an animation clip with the name ‘DeathAnimation’ or call this function only for existing animations.
… when I try to click on the object I am destroying

Alright I figured out that part it was saying I had to change the Animation to legacy, now it is back to destroying the object but is still not creating the animation after the object is destroyed