- Home /
Inverse health bar
I need to make a health bar that decresases from left to right. I have tried this code:
// Life Bar 1
var posX = Screen.width/4 - 248/2;
var posY = 24;
GUI.BeginGroup(Rect(posX, posY,248,24),guiStyle);
GUI.Box(Rect(0,0,248,24),leftLifeBack,guiStyle);
var ratio : float = player1.life/LIFE;
var offset : int = (1-ratio)*236;
GUI.BeginGroup(Rect(6+offset,3,ratio * 236, 18),guiStyle);
GUI.Box(Rect(0,0,236,18),leftLifeFront,guiStyle);
GUI.EndGroup ();
GUI.EndGroup ();
And works. But the problem is that I need to clip the front image by the left instead of clipping by the right.
The front picture is a bar with an angle on the left. http://mugen.weboy.org/hokutonoken-lifebar-by-gal129.html
Does anyone know a solution?
Thank you.
Answer by Bunny83 · Jul 04, 2011 at 02:29 PM
Your problem is that a GUI.BeginGroup act as parent for its contained controls. To keep the bar in place (the GUI.Box) you have to move it in the opposite direction than your Group.
GUI.BeginGroup(Rect(6+offset,3,ratio * 236, 18),guiStyle);
GUI.Box(Rect(-offset,0,236,18),leftLifeFront,guiStyle);
GUI.EndGroup ();
Your answer
Follow this Question
Related Questions
Health Bar Only For Falling Damage 2 Answers
need help with GUI healthbar 1 Answer
Health bar by percentage? (not drawing a box) 4 Answers
Health Bar Centering 4 Answers
Creating a Lifebar with simple GUI in C# 3 Answers