- Home /
animation clip wont play
I have a problem with my animation Clip which is supposed to play when his health is <=0. but all it do is stop running and give me a death point which it's supposed to do. my other animation Clips work fine.
here's my code, it's in C#
public AnimationClip dieClip;
public AnimationClip idleClip;
public AnimationClip runClip;
public int moveSpeed;
public int rotationSpeed;
public int maxdistance;
private bool dead;
void Update () {
if (health > 0) {
moveSpeed = 3;
rotationSpeed = 5;
animation.CrossFade (runClip.name);
Attack ();}
if (Vector3.Distance (target.position, myTransform.position) < maxdistance)
{
animation.CrossFade (idleClip.name);
}
private bool isdead(){
//bool dead = false;
if (health <= 0 && !dead) {
moveSpeed = 0;
rotationSpeed = 0;
animation.CrossFade (dieClip.name);
dead = true;
StartCoroutine ("enemyDead");
collider.enabled = false;
scoreManager.kills += 1;
scoreManager.killsCoins += 1;
}
return dead;
}
}
StartCoroutine ("enemyDead"); what is this coroutine doing
I think that you need to wrap this code with an extra check if the character is not dead.
if (Vector3.Distance (target.position, myTransform.position) < maxdistance)
{
animation.CrossFade (idleClip.name);
}
Because like this it will always crossfade to idle when the distance condition is met.
Answer by edilla · Oct 24, 2014 at 02:31 PM
@CodinRonin if (Vector3.Distance (target.position, myTransform.position) < maxdistance && !dead) { animation.CrossFade (idleClip.name); }
The proper way of pinning the answer for referenceis by marking my comment as answer, and accept is as correct. Cheers.