Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    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:
    4
    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:
    4
    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,510
    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:
    4
    That's much cleaner! Thanks for the reply.
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
  6. OctoBionic_TZ

    OctoBionic_TZ

    Joined:
    Oct 9, 2020
    Posts:
    3
    Hello,
    I'm using this great Timer asset, but I am unable to set 'Start Time' using the Playmaker 'Set Property' action. I can set just about every other property with that action, but not 'Start Time'. I may be overlooking something, but I'd appreciate any help in setting this property dynamically.
    Thanks for any suggestions!
     
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I'm not very familiar with PlayMaker, 'Start Time' is just a standard C# variable in Timer.cs:
    Code (CSharp):
    1. public double startTime;