I’m trying to take my player’s health and display the number over a health bar. As the player looses health, the number drops and the bar shrinks. It works well, but I need to drop the decimals after his current health so I need it as an int. But if I don’t set the current health to a float, the textured health bar doesn’t shrink properly.
I also need the texture bar set as a percent so I can adjust the player max health without having the bar itself grow bigger than the 200 pixles it’s curretly designed to fit into.
In other words, without changing the way I’ve laid this out, I just need to drop the numbers after the decimal point in line 12.
var maxHealth = 500;
var curHealth = 500f;
var healthTexture : Texture;
var emptyTexture : Texture;
function OnGUI() {
GUI.contentColor = Color.black;
GUI.DrawTexture(Rect(20,33,200,14), emptyTexture);
GUI.DrawTexture(Rect(20,33,curHealth/maxHealth * 200,14), healthTexture);
GUI.Label (Rect (25, 30, 200, 50), "Health");
GUI.Label (Rect (100, 30, 200, 50), "" +curHealth);
GUI.Label (Rect (122, 30, 200, 50), "/" +maxHealth);
if(curHealth > maxHealth)
{
curHealth = maxHealth;}
if(curHealth < 0)
{
curHealth = 0;}
}