(I’m sorry if my writing sounds weird. I hope it’s coherent enough to get my point across.) I was following a tutorial by BlackThornProd for hearts to represent the players health instead of using a health bar. The problem I’m having is that I’m not sure how to make it so that when the player collides with an enemy that they lose a heart.
Health Script:
{
public int health;
public int numOfHearts;
public Image[] hearts;
public Sprite fullHeart;
public Sprite emptyHeart;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
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;*
}
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == “Enemy”)
{
//I’m not sure what to put here.
}
}
}
If you need anymore information, let me know. Thank you.