- Home /
Scaling GUI Label not working?
I'm trying to create a health bar that shrinks as the variable health decreases, but it seems to only decrease once health is at 50 or lower. As if it's only going to decrease by half values of health... Is there something I'm not doing right with this code?
GUI.Label (Rect(.06 * Screen.width, .89 * Screen.height, .30 * Screen.width / (100/health), .04 * Screen.height), "" + health, healthStyle);
Thanks if you can help!
Answer by swyrazik · Jul 09, 2013 at 07:53 PM
Try this:
GUI.Label (Rect(.06 * Screen.width, .89 * Screen.height, .30 * Screen.width * (health/100.0f), .04 * Screen.height), "" + health, healthStyle);
My guess is that your variable for keeping health is an int so it would truncate the result at the division (100/health) and thus the wrong behaviour. But if you put 100.0f instead of 100, it gives you the precise result with decimals.
Ahh, simple solution I didn't even think about in the first place! Thanks! :D
Your answer
Follow this Question
Related Questions
GUI adapting to screen resolution? 3 Answers
GUI.Label font size scale - using GUISkin 1 Answer
GUI and Screen Resolution 1 Answer
How do I take maximum screenspace for Gui 1 Answer
How Do I Center A GUI Label? 5 Answers