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
1
Question by Princess · Dec 06, 2010 at 11:08 PM · guitimer

how to I reset a health or progress bar

Hi I am stuck and pls need some help. My game is a wordsearch puzzle which has a progress bar. when the bar is filled, the game ends and the player is expected to have completed the game. The problem is that when the player clicks on the replay button the progress bar doesnt reset like a normer Timer would do. Any ideas pls?

Comment
Add comment · Show 1
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 The_r0nin · Dec 06, 2010 at 11:10 PM 0
Share

Some code would be helpful. How do you declare your progress bar variable, what do you do to reset the game, etc.?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Statement · Dec 06, 2010 at 11:19 PM

Based on your previous information:

if (buttonWasClicked)
{
    progressBar.progess = 0;
}

Based on your update with the link, I am guessing that you want it to be like this:

var barDisplay : float = 0; var pos : Vector2 = new Vector2(20,40); var size : Vector2 = new Vector2(60,20); var progressBarEmpty : Texture2D; var progressBarFull : Texture2D;

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 Update() { barDisplay += Time.deltaTime * 0.05; barDisplay = Mathf.Clamp01(barDisplay); }

function ResetBar() { barDisplay = 0.0f; }

You can then control the bar by setting enabled = true when you want the bar to tick up, and call ResetBar() when you want it to reset (or just modify barDisplay, it runs between 0 and 1).

Comment
Add comment · Show 2 · 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 Princess · Dec 07, 2010 at 11:26 AM 0
Share

Thank you for your response.I got help for the creation of my progress bar from this link:http://answers.unity3d.com/questions/4456. $$anonymous$$aybe this could help. I did try something similer to your answer but still didn't get it to work.

avatar image Princess · Dec 07, 2010 at 03:41 PM 0
Share

thanks alot!!! It worked :-D

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

No one has followed this question yet.

Related Questions

how do I change a gui texture at certain intervals? 1 Answer

how do I make a Time Based Score System? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

GUI Help, timer and counter 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