2d Health System

You could check out this video

It's not for 2D but the logic is exactly the same.