- Home /
How do I make an energy bar drain from the top down.
I am trying to make an energy bar drain from the top down, but the best I can get is having it drain from the bottom up. Does anyone know a way to do this. Here is the code I have right now.
void Start () {
originalHeight= bloodOrb.height;
}
// Update is called once per frame
void Update () {
heightToUse = originalHeight*((TimeToShow - Time.time)/TimeToShow);
}
void OnGUI(){
GUI.BeginGroup(new Rect(34.0f, 34.0f,bloodOrb.width, heightToUse),style);
GUI.Label(new Rect(10,10,bloodOrb.width,bloodOrb.height),bloodOrb,style);
GUI.EndGroup();
}
Answer by mdagreda · Feb 17, 2014 at 12:47 AM
this code worked
void Start () {
originalHeight = bloodOrb.height/2;
sizeToUse = new Rect(startX,startY,bloodOrb.width/2,bloodOrb.height/2);
}
// Update is called once per frame
void Update () {
heightToUse = originalHeight*((TimeToShow - Time.time)/TimeToShow);
sizeToUse.yMin = originalHeight - heightToUse;
}
void OnGUI(){
GUI.BeginGroup(sizeToUse,style);
GUI.Label(new Rect(0,heightToUse-originalHeight,bloodOrb.width/2,bloodOrb.height/2),bloodOrb,style);
GUI.EndGroup();
}
Answer by mattyman174 · Feb 17, 2014 at 12:52 AM
Just flip the GUI Element?
GUI functions can be rotated using GUI.matrix. GUIText and GUITexture elements can't be rotated. When using GUI.matrix in OnGUI, you should reset the matrix after the element you want rotated.
Answer by xt-xylophone · Feb 17, 2014 at 12:47 AM
You can either have something else draw over the top from top-down, covering it downwards. Or whenever you change the height of the bar, you also increase it further down the screen.
For example, a 10px high bar along the top. When you lower the bar by 1, also have it be drawn 1 lower so its now 9px high and 1px from the top.
Your answer
Follow this Question
Related Questions
Bar with segments depending on a value. 0 Answers
Problem Draining Energy Float When Sprinting 1 Answer
How to set high score (best time) with playerprefs 1 Answer
Detect Text in GUI; Print 1 Answer
GUIDrawTexture Based Crosshairs 0 Answers