Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

► Timers & Clocks ◄

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

  1. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Hi, I'm glad you're enjoying.

    Feel free to send an email for an updated script, or you can add these functions to the script as an example

    Code (CSharp):
    1.  
    2. public void IncreaseTimerValue () {
    3.     gameTime += 5.0f;
    4. }
    or this if you want to specify the amount ( -5 would decrease the time value by 5 seconds )

    Code (CSharp):
    1.  
    2. public void IncreaseTimerValue (int value) {
    3.     gameTime += value;
    4. }
    You can also make line 38 in the script a public variable: gameTime . This will allow you to directly modify the timer value without a built in function.

    I'll spend some time tonight adding some built in functionality to modify the timer value and post an update to the store.
     
  2. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    301
    Hi,

    I am interested in this product, I just want to ask couple of questions.

    The feature I am looking is; I have 5 days reward program, User claims the the first reward, and after 24 hours second reward is avaliable to be claimed, etc... I have couple of reward systems like these..

    Does your timer keep counting down when user exit the app, and come back again later ?
    Can I speed up the countdown ? ( Such as watch this video and skip 6 hours in countdown )
     
    Stephen_O likes this.
  3. hanso23

    hanso23

    Joined:
    Jul 22, 2012
    Posts:
    16
    Hey!

    Again sorry for my late reply & thanks for your solution! I've made the gameTime public, so I can access it via playmaker without a problem! Working perfectly!! \o/
     
    Stephen_O likes this.
  4. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    You're welcome, I also submitted an update to the asset to make that change permanent.
     
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.1 submitted.

    • Added 3D Clock model for 3D clock prefab
    • Added Clock Sprite for uGUI clock prefab
    • Added AddTime (float value) method, use negative numbers to subtract or positive to add time.
    • Changed gameTime variable to public so it can be accessed directly if needed.
     
    Last edited: Jul 24, 2020
  6. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Hello,

    The timer will not count down when the app closes. The best way to handle this is to compare Timestamps as your use case requires tracking time outside of a running application.

    You would want to create a timestamp when an event happens (user claims reward) and save that value someplace with playerprefs or on a server. If your app is running you can then calculate the difference between the stored timestamp and the next available time using then use my asset to manage the timer while the application is running.

    I added a method to version 1.1 (currently pending review) to allow users to modify the current time value of a timer, with this method you can use negative numbers to subtract or positive to add time.
    Code (CSharp):
    1. AddTime (float value)
    I can look into adding an option/script to create and check a timestamp value using playerprefs to save the data, I've done this in the past in to manage UnityAds myself so it should not be too time consuming, however I don't know when it will be ready. I will post here with an update soon for this feature.
     
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Timers & Clocks is 30% off for mega sale!
     
  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.1.2 submitted.

    This new version has a minor but useful change:

    • UGUI and 3d analog clock prefabs no longer require a Timer reference, their scripts now contain everything required to make the prefabs work without any configuration.
     
  9. Gatskop_Software

    Gatskop_Software

    Joined:
    Sep 21, 2014
    Posts:
    74
  10. george_00

    george_00

    Joined:
    Oct 23, 2015
    Posts:
    19
    Hello there,

    I have a quick question before I buy: I have a scene in my game where the player goes to a party, and I want a clock to display with the start time (say 8pm) when the scene begins, then I need this clock to run pretty fast, so after a short time it's 11pm and the party is over. Is it possible with this asset to set the start time in this way, and adjust the speed of the clock, so I can control how long the scene lasts?

    I can see in the video that you can call other events from the script - is it possible to set this so I could call them once the timer reaches a specified time, like 11pm?

    Thanks so much for your help.
     
  11. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Thanks for the question. The asset does not currently support that feature.. but I was able to add it without too much effort and it makes sense to add it. I'll submit the update soon; if you decide to buy and want the update sooner, you can email me an invoice number after you purchase and download the asset, then I'll forward you the update.

    With the update, you'll want to create a timer that has the following inspector configurations made:

    Timer State - Counting
    Timer Type - Count Up
    Set Start Time For Count Up - True
    Start Time - 72000 (72,000 into a day would be 8 pm)
    Finish Time - 82800 (82,800 into a day would be 11 pm)
    Timer Speed - increase based on how fast you want time to pass
    Times Up Event - assign your custom event to trigger at the finish time

    Then if you want to use a uGUI or 3D clock prefab, just add it to the scene and make the following inspector configurations:

    Use System Time - False
    Timer - assign the timer reference
     
    Last edited: Jul 24, 2020
  12. george_00

    george_00

    Joined:
    Oct 23, 2015
    Posts:
    19
    @Stephen_O Wow, THANK YOU! That's awesome! I really appreciate your help, I've just made the purchase so I'll send you the invoice number now :-D
     
    Stephen_O likes this.
  13. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.1.3 submitted.

    I had an additional request to add Text Mesh Pro support for UI Text output. I believe the TMPro namespace is available starting in 2018.2 for all projects, so this asset will now have an option to use either the default UI Text or Text Mesh Pro UGUI by selecting the new Text Type > Text Mesh Pro UGUI option in the inspector and assign a new TMP Text component reference.

    • Add option to set start time when a timer is counting up so clock prefabs can be able to read it as a time of day.
    • Option to use TextMeshPro text instead of default Unity text.
    • Version 1.1.3 requires Unity version 2018.2.1 or higher.
     
    Last edited: Jul 24, 2020
  14. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.1.4 submitted.

    • Improved inspector options layout.
     
    Last edited: Jul 24, 2020
  15. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.1.5 is now available

    • Added system time hour offset - allows simulation of timezones for different analog clock objects in the scene.
     
  16. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    29
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    There's no built in feature for time accumulation and saving that data for future use. The timer component is mostly for generic timed events, etc.

    I might take your inquiry and add a system like that in the future, it seems like it would be a good feature to have.
     
  18. chex35

    chex35

    Joined:
    Feb 4, 2019
    Posts:
    2
    Thank you for this! Is there a way to dynamically show milliseconds only after the minutes reaches 00?
     
  19. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    The timer script is basically formatting a float as it counts, you can make a reference to this value and check for when it's below 60.0f (less than a minute) or 1.0f (less than a second), then change the timer format options to only display the field you want.

    Add this example script to the object with the Timer component on it in your scene and it will only show milliseconds once the timer drops below 1 second or show milliseconds and seconds if the timer is less than 60 seconds.

    Example script:
    Code (CSharp):
    1.  
    2. using TurnTheGameOn.Timer;
    3. using UnityEngine;
    4.  
    5. public class FormatTimer : MonoBehaviour
    6. {
    7.     private Timer timer;
    8.  
    9.     void Awake()
    10.     {
    11.         timer = GetComponent<Timer>();
    12.     }
    13.  
    14.     void Update()
    15.     {
    16.         if (timer.gameTime < 60.0f) // timer has less than 60 seconds - only display seconds and milliseconds
    17.         {
    18.             timer.timerFormat.milliseconds = true;
    19.             timer.timerFormat.seconds = true;
    20.             timer.timerFormat.minutes = false;
    21.             timer.timerFormat.hours = false;
    22.         }
    23.         else if (timer.gameTime < 1.0f) // timer has less than 1 second - only display milliseconds
    24.         {
    25.             timer.timerFormat.milliseconds = true;
    26.             timer.timerFormat.seconds = false;
    27.             timer.timerFormat.minutes = false;
    28.             timer.timerFormat.hours = false;
    29.         }
    30.     }
    31. }
    32.  
     
  20. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.1.7 submitted.

    • Changed gameTime from a float to double, this allows for 922337193600 max seconds allowed, which is 10,675,199 days. This is useful for saving a players game progression, with float values, the timer would previously break down due to floating point accuracy.
    • Added 'days' as a display option.
    • Fixed a bug where the save session Timer script would not always save/load the correct value.
    • Added PDF documentation.
     
    Last edited: Jul 24, 2020
  21. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.2 submitted.

    • Updated tutorial.
    • Updated documentation.
    • Increase max TimerSpeed from 100 to 10000.
    • Add 3D Analog Stopwatch prefab.
    • Add UI Analog Stopwatch prefab.
    • Changed Timer variable setStartTimeForCountUp name to setCountUpStartTime.
    • Moved Destroy Objects function to it's own class.
    • Moved Load Scene function to it's own class.
    • Fixed a bug where using a timer without a text component assigned would not properly output non-system time to analog prefabs.
    • Fixed a bug where some Timer properties were not properly serialized and did not support undo/redo or trigger a scene change.
     
    Last edited: Sep 22, 2020
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.3 submitted



    • Timer script refactor.
    • Updated tutorial.
    • Updated documentation.
    • Added comments to Timer methods.
    • Added UI Digital Timer prefab.
    • Added 3D Digital Timer prefab.
    • Added tooltip descriptions to Timer script.
    • Removed Timer.setCountUpStartTime option, Timer.startTime is now always exposed.
    • Removed Timer prefab from Resources folder, it's now in the prefabs folder, renamed to 'UI Digital Timer'.
    • Removed Timer Format options, all formatting options are now controlled via 'Display Options'.
    • Moved Enums to their own script files.
     
  23. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.3 is now available.
     
  24. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.3.1 submitted.

    • Added 'Loop' option to Timer.
     
  25. awroosevelt

    awroosevelt

    Joined:
    Jul 13, 2018
    Posts:
    2
    Hi. so far I'm loving this. I do have a question though, I'm wanting to loop a timer to assist with a day/night cycle (torch on at night, then off in the morning). I'm able to get the timer itself to restart with a "times up event', but when it restarts, the events don't re-trigger. The clock seems to be working (verified with on screen UI text). Am I missing something, or just trying to do the impossible?

    PS. I see that you just added a "loop" function built right into the timer, but i don't see it. I just got the asset this morning.
     
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Unity takes time to review the asset, since it's Friday, it may not be approved until Monday or later.

    If you like, send me an email with invoice number stephen@turnthegameon.com and I'll give you the updated asset package.
     
  27. awroosevelt

    awroosevelt

    Joined:
    Jul 13, 2018
    Posts:
    2
    Thanks for the updated script. Unfortunately, it didn't solve the issue I'm having. The timer does in fact loop, but after the first time though, it no longer triggers the events. I'm not sure if it's something that I'm doing wrong, or just a limitation of the script. Anyway, I though you might want to know. I still find TimerAndClocks very useful for other things, but without the events working on each loop, I'm not sure that it's useful for what I'm trying to achieve.
     
  28. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    It sounds like you're using the `Time Events`, I only tested the `Times Up Event` initially. I apologize for that, I just added a fix for this.

    It would be helpful to me if you have additional feedback to a request or support, please contact me in one place, so I only need to respond in one place (prefer here or email). We started on youtube, moved here, then email, now we're back here. I'll reply with a new package for you on email since you're requesting the package before approval as I can't post the package publicly via forum.
     
  29. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.3.1 resubmitted.

    • Added 'Loop' option to Timer.
    • Ensure 'TimeEvents' and 'TimesUpEvent' are both triggered when 'Loop' is enabled.
     
  30. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,299
    Version 1.3.1 is now available.
     
unityunity