- Home /
Scrollbar Thumb Scaling
I'm using this piece of code as an health bar. It works fine really, just a quick question. The texture of my Thumb which indicates the health (uiHP variable) stretches when scaled. I wondered if instead of stretching it could just not show a percentage of the bar. I attached an image to get a better idea of what I'm trying to achieve.
The code I'm currently using
GUI.HorizontalScrollbar(Rect(100,80,BarLength,BarHeigth), 0, uiHP,0, 100);
Anyone any idea how to achieve this?
maybe drawing a rectangle over your healthbar with the color of your background? such as:
void Update(){(NOTE: Or Function Update())
ui$$anonymous$$issingHP = BarLength - uiHP;
}
void OnGUI(){(NOTE: Or Function OnGUI()) {
GUI.HorizontalScrollBar(Rect(100,80,BarLength,BarHeight),0,uiHP,0,100);
GUI.Box(Rect(ui$$anonymous$$issingHP,80, uiHP(NOTE: not sure on math), BarHeight));
(NOTE: I didnt run this in unity, so it may need some adjustments, but this is to give you an idea of how to solve your problem)
}
This wouldn't be an optimal solution... The textures you see here are just placeholders, but eventually the background of the scrollbar will be transparent. If I try your approach this will mean you will still see the actual health's texture through it.
Thanks for the suggestion though, it might have been really helpful if I wasn't so ridiculously picky =P