player life hearts

   [SerializeField]
    private Image[] playerHealthImages;

    [SerializeField]
    private Sprite fullHeart;

    [SerializeField]
    private Sprite emptyHeart;

    [SerializeField]
    private int Hearts;

    [SerializeField]
    private int numOfHearts;


 void Update()
    {
     
        if (dragon.IsDead)
        {
            LoseHeart();
        }
    }



LoseHeart()
{
   if (Hearts > numOfHearts)
        {
            Hearts = numOfHearts;
        }
        if (Hearts == 0)
        {
            StartCoroutine(GameOver());
        }
for (int i = 0; i < playerHealthImages.Length; i++)
        {
            if (i < Hearts)
            {
                playerHealthImages[i].sprite = fullHeart;
            }
            else
            {
                playerHealthImages[i].sprite = emptyHeart;
            }

            if (i < numOfHearts)
            {
                playerHealthImages[i].enabled = true;
            }
            else
            {
                playerHealthImages[i].enabled = false;
                Hearts--;
            }
}
        }

here i try eaxh time player dead bool is true, just one heart image get empty and life counts –

but it does not work.
how can you subtract one heart from player and remove 1 heart sprite?

any idea pleased.

no answer!

I’d probably start off with Hearts–; immediately. Then check if Hearts == 0, then update the graphics.

It also seems very strange for you to call LoseHeart in the Update method. If `dragon.IsDead’ for several frames in a row, the player will die instantly. You probably need to call LoseHeart in response to a specific event happening, like the player touching an enemy collider.

Hey. Did you figure it out?