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 ShinyTaco · Jan 30, 2013 at 01:41 PM · timerbarprogress

How to Subtract Time from Progress Bar Timer?

Hello,

I have a graphic progress bar which I declare here:

 var barDisplay : float = 0;

It counts up from zero and if barDisplay is >=1 the game is over. That works fine.

I also have:

 function subtractTimeFromBar () {
     
     //How do You Subtract Time from barDisplay here?
     Debug.Log ("addTimeToBar Called");
 
 }

Which is called from a collision. This also works and is getting called as subtractTimeFromBar shows in the console.

When addTimeToBar is called, I would like to subtract anyNumberIsFine amount of time from the timer.

I'm not sure how to do this.

Any help is really appreciated. Thanks in advance!

Comment
Add comment · Show 2
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 Jeffom · Jan 30, 2013 at 01:45 PM 0
Share

It would help if you could tells us how you're calculating the time from the progress bar and how your gameobject's components are organized.

avatar image ShinyTaco · Jan 30, 2013 at 02:18 PM 0
Share

In my Update function I have:

 barDisplay = Time.time * .05;

To count the timer up.

I call subtractTimeFromBar() from another script:

 function OnTriggerEnter (collision : Collider) {
 
 //doStuff
 
 }

The progress bar is in:

 function OnGUI()

Thanks.

2 Replies

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

Answer by ShinyTaco · Jan 31, 2013 at 01:43 PM

This wasn't working because my timer was using Time.time. I had:

 barDisplay = Time.time * .05

and should of used just counted up from 0.001

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 Dave-Carlile · Jan 30, 2013 at 01:52 PM

Just subtract off x from the barDisplay variable. It would probably be best to pass in x as a parameter to your subtractTimeFromBar function.

 barDisplay = barDisplay - x;
 if (barDisplay < 0) barDisplay = 0;

Or, since you know barDisplay will always range from 0 to 1, you can use the Mathf.Clamp01 function to remove the if...

 barDisplay = Mathf.Clamp01(barDisplay - x);
Comment
Add comment · Show 3 · 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 ShinyTaco · Jan 30, 2013 at 02:21 PM 0
Share

Hey, thanks for the help. I tried:

 barDisplay = barDisplay - x;
 if (barDisplay < 0) barDisplay = 0;

and

 barDisplay = $$anonymous$$athf.Clamp01(barDisplay - x);

Still didn't work.

avatar image Dave-Carlile · Jan 30, 2013 at 02:24 PM 0
Share

"Didn't work" isn't really helpful for us. What didn't work? What happened?

avatar image ShinyTaco · Jan 30, 2013 at 02:26 PM 0
Share

The timer just kept going, the game went on like normal.

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

11 People are following this question.

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

Related Questions

Load bar in GameObject 2 Answers

progress bar 1 Answer

How to create a vertical circular progress bar 1 Answer

Problem ProgressBar with health + Time the poison 1 Answer

Progress of loading level 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