Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

► Timers & Clocks ◄

Discussion in 'Assets and Asset Store' started by Stephen_O, Aug 8, 2015.

  1. cwelbon

    cwelbon

    Joined:
    Aug 14, 2017
    Posts:
    3
    Hi, your asset has been really useful so far. I've run into a situation where I'd like to show the elapsed time in a count-up infinite timer only in seconds (out to milliseconds), rather than mm:ss. So 75.438 instead of 1:15.438. I've looked into formatting the output text differently, but haven't gotten it to work, and wonder if I'm overlooking an easy or obvious way?
     
  2. cwelbon

    cwelbon

    Joined:
    Aug 14, 2017
    Posts:
    3
    Decided to modify FormatSeconds to convert minutes received from the TimeSpan object into seconds and add the result to the seconds property of the TimeSpan, and pass that result in the formatted string. By turning off the minutes display option, I can show only raw seconds. Not sure if there's a better way but this seems to be working.

    Code (CSharp):
    1.  
    2. minute = t.Minutes;
    3. //convert any minutes to seconds and add result to second to show raw time in sec.
    4. second = t.Seconds + t.Minutes * 60;
    5. millisecond = t.Milliseconds;
    6. //To show raw seconds instead of mm:ss, we pass the result of the above calculation, instead of the seconds property of the timespan object.
    7. return String.Format (d + h + m + s + ms, t.Days, t.Hours, t.Minutes, second, t.Milliseconds);
     
  3. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,500
    That sounds like it's working for you, which is good.

    instead of calculating, you can also replace everything on lines 153-159 or 164-174 with
    Code (CSharp):
    1. return gameTime.ToString("F3");
    The unformatted gameTime variable is the total seconds that gets formatted for the fancier options.

    I'll try to get an update in that can provide this as an option from the inspector.
     
  4. cwelbon

    cwelbon

    Joined:
    Aug 14, 2017
    Posts:
    3
    That's much cleaner! Thanks for the reply.
     
unityunity