[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.