- Home /
scrollbar
code:
var health = 50;
function OnGUI () {
GUI.HorizontalScrollbar (Rect (25, 25, 50, 10), 0, 10, health, 10);
}
i want the bar to start at the left and be longer if health is higher but i forgot what numbers to put where
Then consult the documentation. GUI.HorizontalScrollbar is easily googled:
http://unity3d.com/support/documentation/ScriptReference/GUI.HorizontalScrollbar.html
Its page tells you exactly what each parameter is.
Watch this video tutorial on How to make a health bar , it should help. The GUI part of it starts around 06:30 or so. The parameter's should still work basically the same for your scrollbar if that's really what you want to use for it. There's a lot of other unity health bar stuff all over the place in here too if you just search for it.
i didnt understand which numbers to put where and my internet is so bad that a video that is more than 6:30 will take over an hour to load
Answer by aldonaletto · Dec 15, 2011 at 01:06 AM
That's an interesting "misuse" of this function - it's intended to control something, not to show a value - but yes, it can be used as a progress bar:
var health: float = 50; var maxHealth: float = 100; var dummy: float = 0; // "sticks" the button at the left
function OnGUI () { GUI.HorizontalScrollbar (Rect (25, 25, 120, 20), dummy, health, 0, maxHealth); } You must never allow the health to be lower than zero or greater than maxHealth, or the bar will grow to the wrong side (to the left). Another problem is that the bar never reaches zero length, even with zero health (and negative health will make it grow to the left, as mentioned above).