- Home /
Fill rectangle from bottom to top
I currently have this code:
// draw the background:
GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
GUI.DrawTexture(new Rect(0, 0, size.x, size.y), progressBarEmpty);
// draw the filled-in part:
GUI.BeginGroup(new Rect(0, 0, size.x, size.y * barDisplay));
GUI.DrawTexture(new Rect(0, 0, size.x, size.y), progressBarFull);
GUI.EndGroup();
GUI.EndGroup();
This fills my image smoothly from top to bottom according to `barDisplay`. I wish my texture to be filled from bottom to top..
How can i do that?
Answer by Krapylet · Dec 18, 2016 at 01:21 PM
I know this is old, but better late than never, in case someone have similar issues: One way to do it: barDisplay variable determines the size of the rectangle. The code from line 5 should be changed so you change the point of the BEGINNING of the rectangle instead of changing the SIZE of the rectangle. So move barDisplay to replace the second zero in the Rect. I guess you must experiment with how quickly barDisplay increases.
Here is my snippet (note I changed the indentation to a HTML style:
void OnGUI()
{
InitStyles();
// main draw area
GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
{
GUI.Box(new Rect(0, 0, size.x, size.y), "", bgStyle); // draw the background:
// define filling area bounds
GUI.BeginGroup(new Rect(0, 0, size.x, size.y));
{
GUI.Box(new Rect(0, barDisplay, size.x, size.y ), "", frontStyle); // draw the filled-in part:
}
GUI.EndGroup();
}
GUI.EndGroup();
}
void Update()
{
if (barDisplay >= size.y)
print("Done!");
barDisplay += Time.deltaTime * timerSpeed;
}
Your answer
Follow this Question
Related Questions
Help with destroying guiRect? 0 Answers
My GUI IS Bugging Out. Can Anyone Help? 0 Answers
gui draw rexture problem 1 Answer
GuiTexture above 3D objects 1 Answer
GUI changes when game runs full screen 2 Answers