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 Nynex71 · Dec 30, 2010 at 06:05 PM · timerlabelcountdown

Countdown Through a Label?

Is it possible to have a label and have it countdown in seconds and then have it restart that timer after that time was used up? Im using this for a pay day type thing and this is the last thing i need in it. NOTE: i use c# and i plan on adding this to a current script i already have. If it is please respond and all help is appreciated.

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 Justin Warner · Dec 30, 2010 at 06:12 PM 0
Share

http://answers.unity3d.com/questions/22858/timer-runtime-problem http://answers.unity3d.com/questions/15471/timer-reset-after-elapsed-time http://answers.unity3d.com/questions/12992/count-down-timer-per-second

3 Links, should help.

avatar image Nynex71 · Dec 30, 2010 at 06:14 PM 0
Share

thanks u could have posted that as an answer and i would have accepted it.

1 Reply

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

Answer by Ejlersen · Dec 30, 2010 at 06:28 PM

Another silly way of doing it. Probably not the best conversion to string method, but it works :)

public class CountDown : MonoBehaviour { public float t = 180.0f; // Seconds

void Update() { t -= Time.deltaTime;

 if (t < 0.0f)
     t = 180.0f;

}

private string ConvertTimeToString() { int hours = Mathf.FloorToInt(t / 3600); int minutes = Mathf.FloorToInt((t % 3600) / 60); int seconds = Mathf.FloorToInt(t) % 60;

 return hours.ToString("00") + ":" + minutes.ToString("00") + ":" + seconds.ToString("00"));

}

void OnGUI() { GUI.Label(new Rect(32.0f, 32.0f, 128.0f, 32.0f), ConvertTimeToString()); } }

Comment
Add comment · Show 5 · 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 Nynex71 · Dec 30, 2010 at 06:41 PM 0
Share

works great but its set to 2:50 and not 3:00 and looking at that script i cant find out what to change without breaking everything else.... i do see the variable but the problem is that its set to 10000.0f and i only need it to be 180.0f but if that is 2:45 than i need to raise it but what should i raise it to?

avatar image Bunny83 · Dec 30, 2010 at 06:56 PM 2
Share

The time is in seconds. 10000sec = 2h 46m 40sec If you want 3m = 180sec that would be right. I don't know why you subtract 50 per sec? you should subtract only deltaTime

and the string format can be done with hours.ToString("00") + ":" + $$anonymous$$utes.ToString("00") + [...]

avatar image Ejlersen · Dec 30, 2010 at 06:57 PM 0
Share

Well, if you want it to show 3 $$anonymous$$utes, then just set it to 180.0f. Oh, I had some debug code in it, that made the timer go 50 times faster than normal. Just remove the * 50.0f, as I have done in the code now.

avatar image Ejlersen · Dec 30, 2010 at 06:58 PM 0
Share

Nice, Bunny. I did not know that :)

avatar image Nynex71 · Dec 30, 2010 at 07:07 PM 0
Share

yeah thanks man really helped me

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

When Score goes up by 25 change timer value 1 Answer

Countdown timer trouble? 1 Answer

Countdown to start level 1 Answer

Timer doesn't work properly 2 Answers

end game condition 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