Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kodagames · Sep 05, 2012 at 06:13 AM · counterprogress bar

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!");    
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with basic magic system 0 Answers

Cloud recognition in Vuforia 0 Answers

highscore/display system for multiple levels 2 Answers

How can I get the full path of an asset on Android? 1 Answer

NullReferenceException: Object reference not set to an instance of an object? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges