I reversed the hits logic to produce multiple hit blocks that show damage on last two hits. What do you think?
[SerializeField] Sprite[] sprite;
[SerializeField] int numberOfHits = 1;
private void OnCollisionEnter2D(Collision2D collision)
{
numberOfHits--;
if (tag == "breakable")
{
if(numberOfHits <= 0)//destoy block
{
DestroyBlock();
}else //change pictue
{
ChangeImage();
}
}
}
private void ChangeImage()
{
if (numberOfHits < 3)
{
//reduce numberOfHit to reflect image status
//last state (0) is destroy, so 2 and 1 are image changes
spriteRenderer.sprite = sprite[numberOfHits - 1];
}
}