Hello, i’m new to programming and I’m stuck at this:
I’m creating a health system and it’s all good so far, but I need the health to stop at “0”, but instead it goes down and down to negative numbers. How can I solve this? Thanks in advance.
You can do it like:
if(health<0) health = 0;
or
health = Mathf.Clamp(health,maxhealth,0);
Mathf.Clamp returns the value between 0 and max health. Read more here.
if (health <= -1)
{
health = 0;
}