Need help with a Health bar script for stage Boss character

I have an issue that i am confused about. I tried making the same type of health bar trigger script for a Boss character like i did for my Player (which works perfectly btw) but the Boss’s health bar when it depletes to 0 it doesnt trigger its death animation BUT my debug log will show “Boss Defeated” letting me know it happened partially. when i remove the health code it triggers it 100% fine showing “stage clear” etc. So i cant tell what i am doing wrong now.

Here is the code below and all that is attached to it.

[Header("BossStatus")]
        public int maxHealth = 100;
        public int currentHealth;
        public HealthBar bossLife;


void Start()
        {
            currentHealth = maxHealth;
            bossLife.SetMaxHealth(maxHealth);
           
        }




public void TakeDamage(int damage)
        {
            bossLife.SetHealth(currentHealth);
            currentHealth -= damage;

            anim.SetTrigger("Hit");
            if (currentHealth <= 0)
            {
                Killed();
            }


        }

And of course theres a Killed state after that too that activates fine if i dont have the bossLife.SetHealth expressions there.

So i just want to figure out why that when my Boss’s life meter fully depletes it doesnt trigger the Killed state animation now like it does for my player’s script when its pretty much the same set up (?)

Thanks for any advice. suggestions. Code tips etc. In the meantime ill still be figuring it out as i wait!

What does Killed() look like? I’d also like to see what the animation tree looks like too, along with the parameters.

Killed looks like This which works the same way fine for my player.

void Killed()
{

Debug.Log(“Boss Defeated!”);

anim.SetBool(“Killed”, true);

//Disable enemy
GetComponent().enabled = false;
this.enabled = false;

GetComponent().enabled = true;//
this.enabled = true;

}

and the animation Tree (below) for the boss currently

Does the transition to IdleCyclops have the condition only when Killed is false?

Yes

Alright, I guess this should’ve been asked about earlier, but what does your HealthBar code look like?

Currently

public class HealthBar : MonoBehaviour
    {
        public Slider slider;
        public Gradient gradient;
        public Image fill;

        public void SetMaxHealth(int health)
        {
            slider.maxValue = health;
            slider.value = health;

            fill.color = gradient.Evaluate(1f);
        }

        public void SetHealth(int health)
        {
            slider.value = health;

            fill.color = gradient.Evaluate(slider.normalizedValue);
        }

    }

Like i said it works fine for the player having the killed animation trigger when its attached to the collision script. But for some odd reason the results arent the same 100% for the boss character. The life bar drains when hit but when its at 0 it doesnt do what its supposed to do like it does for the Player triggering the void killed state.

Half way fixed it btw. Bar goes down to a certain point then it triggers the boss killed state prematurely. I have to play with the damage numbers a bit to i guess balance it so if i keep attacking it properly goes to that state at 0. But In the end when the Boss is at red life ill have it trigger a more aggressive behavior before it dies.

Sorry I wasn’t able to help, nothing seems to be causing the problem in the given stuff. I’d recommend isolating this stuff in its own environment and see if it works incase something else might be affecting your code.

Yeah thats what ive been trying to do. it started working a bit better