So, I have 2 animations attack and idle, idle is a loop and attack is set to once. I have the sprite with the sprite animator and this code below attached to the sprite. The animations work well the idle loops, but when I set attack to true the attack animation plays forever even though it is set to once. It seems AnimationCompleted never gets hit, am I doing something wrong with AnimationCompleted? I want the animation to just play once then go back to idle.
public bool attack { get; set; }
private tk2dSpriteAnimator anim;
void Start() {
anim = GetComponent<tk2dSpriteAnimator>();
attack = false;
}
void PlayIdle(tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip) {
anim.Play("idle");
}
void Update() {
if (attack) {
if (!anim.IsPlaying("attack")) {
anim.Play("attack");
anim.AnimationCompleted = PlayIdle;
}
}else{
if (!anim.IsPlaying("idle")) {
anim.Play("idle");
anim.AnimationCompleted = null;
}
}
}