Using one variable instead of two

Hello there, in my opinion it’s easier using only one variable for the HP of the blocks.

So on your config params you cna use

[SerializeField] int blockHP = 2;

and in the function OnCollisionEnter2D

if (tag == “Breakable”)
{
blockHP–;

        if (blockHP == 0)
        {
            DestroyBlock();
        }
            
    }

What do you guys think? For me it’s more intuitive

1 Like

If it ends up working out long term than I don’t see any problem.

This seems clever. The only thing I would change is say

if (blockHP <= 0)
{ ... }

That way if you have a weird double-hit on a frame, it won’t go to negatives and exist forever.

Privacy & Terms