Unable to play Death Animation. Parameters missing?
I am trying to play a Death Animation using the Animator. I select my animation and the preview works. But when i go into the game, I get an error saying ---"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."--- I tried changing it to legacy and the error goes away but the amination is never played when enmeyHealth reaches 0. So I think that my probles lies in creating a new parameter that checks if "isDead" inside the Animator in order to play the deathAnimation. However, I have problems coming up with a logic or the syntax to do so. Can anyone please help? Here is the code I am using:
var Health = 100; var animDie : AnimationClip; // Drag your animation from the project view in here (to inspector) var isDead = false;
function Update () { if(Health <= 0 && isDead == true){ //this.gameObject.GetComponent.().Play("deathAnimation"); Dead(); } }
function ApplyDamage (TheDamage : int){ Health -= TheDamage; }
function Dead(){ GetComponent.().Play(animDie.name); //GetComponent.().Play("deathAnimation"); Destroy(this.gameObject, animDie.length); }
 #pragma strict
 
 var Health = 100;
 var animDie : AnimationClip; // Drag your animation from the project view in here (to inspector)
 var isDead = false;
 
 
 
 function Update () {
     if(Health <= 0 && isDead == true){
     //this.gameObject.GetComponent.<Animation>().Play("deathAnimation");
         Dead();
     }
 }
 
 function ApplyDamage (TheDamage : int){
     Health -= TheDamage;
 }
 
 function Dead(){
     GetComponent.<Animation>().Play(animDie.name);
     //GetComponent.<Animation>().Play("deathAnimation");
      Destroy(this.gameObject, animDie.length);
 }
Answer by GamingOink · Mar 31, 2017 at 05:51 AM
Well first of all I think your variable isDead should be a boolean. Booleans have two states: true or false. Just like how ints and floats differ. Next I dont see any code where your variable isDead is set to true? This makes it so isDead is always false and your if statement never plays:
 if(Health <= 0 && isDead == true){
  //this.gameObject.GetComponent.<Animation>().Play("deathAnimation");
      Dead();
  }
I dont know if I am correct but hopefully this helps. Cheers!
Your answer
 
 
             Follow this Question
Related Questions
I can't see or access a state in the Animation Controler 1 Answer
Logic for a lot of animations 0 Answers
Character rolls forward,but slides back after animation 2 Answers
Animation Trigger (Rpg Kit) 1 Answer
i just wanna know how to make this initial position to be a default value?please help me 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                