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 /
This question was closed Dec 06, 2013 at 04:56 PM by AlucardJay for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MattBee · Dec 06, 2013 at 04:39 PM · timertimer-script

Countdown timer?

Okay, I have the code for a countdown timer, I get how that works. My only problem is how would I have it countdown in a time format. So that, say I have 2 minutes, it'll go from 2:00 to 1:59, 1:58 and so on.

The code I'm using is C# so any code posted would be preferable in C#

Thanks ;)

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 AlucardJay · Dec 06, 2013 at 04:56 PM 0
Share
  • http://answers.unity3d.com/questions/45676/making-a-timer-0000-$$anonymous$$utes-and-seconds.html

  • http://xeophin.net/en/blog/2010/10/18/how-format-time-string-c-unity-3d

  • http://answers.unity3d.com/questions/348742/time-formatting.html

  • http://answers.unity3d.com/questions/259482/format-string-$$anonymous$$utesseconds.html

  • http://answers.unity3d.com/questions/25614/how-do-i-format-a-string-into-days$$anonymous$$uteshoursseco.html

  • google is your friend!

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by violence · Dec 06, 2013 at 04:51 PM

I dont know C# so this is all pseudo code, it should be pretty easy:

Have your total amount of time be in seconds. Make sure your values are all ints, as this will all be integer division for ease of use with remainders.

minutesDisplay = seconds / 60

secondsDisplay = seconds - (minutesDisplay*60)

then print to a guiLabel (minutesdisplay + ":" + secondsDisplay)

you will need some conditional formatting for displaying a zero in front of the digit when the secondsDisplay number is less than 10

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 Spinnernicholas · Dec 06, 2013 at 05:02 PM 0
Share

Here is a timer class in C#:

 public Class Timer:
 {
   public float timer;
 
   public Timer()
   {
     timer = 0;
   }
 
   public Timer(float startTime)
   {
     timer = startTime;
   }
 
   public void countUp(float seconds)
   {
     timer += seconds;
   }
 
   public void countDown(float seconds)
   {
     timer -= seconds;
   }
 
   public string toString()
   {
     return ((int)(timer/60)).toString() + ":" + ((int)(timer%60)).toString();
   }
 }
avatar image Spinnernicholas · Dec 06, 2013 at 05:04 PM 0
Share

You might need to override toString().

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with "stun"-timer after player is being hit 1 Answer

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

How do I implement a timer into this script that will record the total time the player has played. 2 Answers

How can I add a timer that will start when the game starts and stop when the game ends and records it? 1 Answer

Delay between throwing/firing 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