Hello. I have a gui box im using as a health bar. A gui box’s size is only 0.0 to 1.0, but of course the characters health is going to be some higher integer. How do you formulate the health to be represented for the health bar? I have no idea on how to calculate health/totalHealth, ie: 231/450 to fit inside 0.0 - 1.0
bardisplay is a float, so if it equals .5, the health bar is half full
GUI.Box ( Rect (screenPosition.x , Screen.height - screenPosition.y - size.y , size.x * barDisplay, size.y),"");
Use InverseLerp, which returns 0.0 to 1.0.
You need to store the maxHealth for your character, as well as their current health.
(float)currentHealth/(float)maxHealth will give you a value between 0.0 and 1.0 (assuming that you never let currentHealth go below zero or above maxHealth)
Use something like this:
GUI.Box ( Rect (screenPosition.x , Screen.height - screenPosition.y - size.y , actualLifeAmount/maxLifeAmount, size.y),"");
of course you need to have those two variables declared and filled, you can update the actualLifeAmount in the update, or every time the character recieves damage, to avoid unnecesary loads.