- Home /
 
Progress Bar Display help (Bonus)
Hello,
I found a progress bar (Thanks WillGoldstone!) which looks and works well for my current project but Im not sure how to make use of it and was hoping I could get some help?
What Im hoping for is when the progress bar reaches the end (progressBarFull) it will start over again (progressBarEmpty) then print("BarDisplay BONUS!"); then start climbing again to the end (progressBarFull) and repeat this process over and over. I hope that makes sense?
Help solving this would be great and an explanation with it would be absolutely amazing! (still learning). Thanks in Advance.
 var barDisplay : float = 0;
 var pos : Vector2 = new Vector2(20,40);
 var size : Vector2 = new Vector2(60,20);
 var progressBarEmpty : Texture2D;
 var progressBarFull : Texture2D;
 var howFast : float = 0.05;
 
 function Update()
 {
     // for this example, the bar display is linked to the current time,
     // however you would set this value based on your desired display
     // eg, the loading progress, the player's health, or whatever.
     barDisplay = Time.time * howFast;
 }
 function OnGUI()
 {
 
     // draw the background:
     GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
         GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);
 
         // draw the filled-in part:
         GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
             GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
         GUI.EndGroup ();
 
     GUI.EndGroup ();
 } 
 function DisplayBonus()
 {
     print("BarDisplay BONUS!");    
 }
 
              Answer by fafase · Sep 05, 2012 at 06:16 AM
You'd rather use Time.deltaTime, at least that is what I would go for.
 var timer:float=100;
 function Update(){
   timer -= Time.deltaTime;
   if(timer<0)timer = 100;
 }
 
               This will last 100s (so 1m40s). Every frame you subtract deltaTime and when reaching 0 bam!!! back to 100. You use timer, the same way as you used barDisplay for the GUI.
There are other ways but this one is quite simple.
Answer by kodagames · Sep 06, 2012 at 01:37 AM
Thanks Guys! Greatly Appreciated!!!
  barDisplay += Time.deltaTime * howFast;
             
      if ( barDisplay >= 1.0 )
      {
          barDisplay = 0.0;
      }
 
               I almost had it the only thing that was missing was the += and the Time.deltaTime also makes more sense :) Again Greatly appreciated! I hope this helps someone else as well.
Your answer