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