Animation Ignores Script
I wrote a death animation script:
#pragma strict
var health: float;
var healthdrop: float;
var starthealth: float;
var person: Animation;
function Start () {
health = starthealth;
}
function Update () {
if(health <= 0){
person.Play("death");
}
}
function OnTriggerEnter (other:Collider) {
if(other.gameObject.tag == "Bullet"){
Destroy(other.gameObject);
health = health - healthdrop;
}
}
I set starthealth to 100, healthdrop to 20 and I set the animation in the inspector as this:
As you can guess, I want to play the animation once the health hits 0, but it plays the animation immediately after scene starts.
What can I do to run the animation if (health <= 0) ?
Answer by incorrect · May 16, 2016 at 04:16 PM
You can find an answer in Animation section of Tutorials.
So look all the tutorials, try to make the same. If you will not succeed after that - probably the problem is that you don't put much effort to achieve the result.
In this case I guess your "starthealth" variable is set to zero in the inspector. Otherwise it should work as expected.
Answer by newGuyInThat · Nov 14, 2016 at 11:18 PM
You could do it with Animator, You must create an Animator, next add animations to it, and create conditions. In this case you can use bool or trigger. Script have to change it's value.
Your answer
Follow this Question
Related Questions
No Loop Time Options in Animation Inspector 1 Answer
I cannot drag the animations into inspector please help [code snippet included] [C#] 0 Answers
How to use an animation with a script?(JS) 0 Answers
Can't add an animation variable into the script 2 Answers
How to create keyframe from animation tab with helped script? 0 Answers