How to let death animation play when enemy dies, and stop player from taking damage

I am currently working on a 2D dungeon crawler similar to binding of isaac, and I’ve tried searching for the answer to this question but can’t find anything that works for me. Essentially, once the player’s health reaches 0, I want the death animation to play, but it gets locked onto the first frame and I can’t quite figure out how to make the animation play out fully in the inspector or via code. What kind of animator settings/script will I have to modify in order to let the animation complete its cycle? I have attached the player health code below (some of it might be a bit clunky or messy, especially because I’m not sure what to put in the IsDead function). Thanks for your help!

public class PlayerHealth : MonoBehaviour
{
    public int health;
    public int numOfHearts;

    Animator anim;
    public Image[] hearts;
    public Sprite fullHeart;
    public Sprite emptyHeart;
    private GameObject player;
    

   

    private void Start()
    {
        anim = GetComponent<Animator>();
        player = GameObject.FindWithTag("Player");

    }


    private void Update()
    {
        if (health > numOfHearts)
        {
            health = numOfHearts;
        }
        
        for (int i = 0; i < hearts.Length; i++)
        {
            if (i < health)
            {
                hearts*.sprite = fullHeart;*

}
else
{
hearts*.sprite = emptyHeart;*
}
if (i < numOfHearts)
{
hearts*.enabled = true;*
}
else
{
hearts*.enabled = false;*
}
}

if (IsDead)
{
anim.SetTrigger(“playerDead”);

}

}

public void Damaged()
{
if (IsDead == true)
{

}

health -= 1;
if (health < numOfHearts)
{
numOfHearts = health;
}

}

public bool IsDead
{
get
{
return health == 0;
}
}
}

try removing the is dead bool from the bottom and instead have it up the rest of the variables and then in the update function do: if (health <= 0) {isDead = true;} else {isDead = false;} it will call it faster and be less buggy later on, also i recomend changing most int’s to floats (this might not help with the bug but it will make it easier to use later, this is my opinion you can do whatever you want) also i recomend using an animation field (the animation tab on the scene view) so that you can make smoother transitions on the animations while also making some of them automatic (find a tutorial online there are really easy to use i recomend brackeys tutorial on youtube) + can you show us the animation in the animation editor and what happens when you die i dont know if its a script problem