Search Unity

► 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,510
    A small, yet powerful collection of drag-and-drop timer and clock prefabs. Use these prefabs to make displaying time, or configuring logic that can trigger a time’s up event quick and easy.



    Asset Store
    Discussion Forum


    Timer Prefab:
    • 3 modes: Count-down, Count-up, and Count-up infinite
    • Loop
    • Adjustable speed
    • Display current system or UTC time
    • Inspector UnityEvent for time’s up
    • Inspector List of UnityEvents triggered at assigned times
    • Time string toggles for milliseconds, seconds, minutes, hours, and days
    • Output time string to Unity Text or TextMeshProUGUI components
    Double value type supports up to 922337193600 seconds (10,675,199 days)
    • Add multiple timers to your scene for different purposes
    • Optional 'SaveSessionTimer' script. Add this script to a timer object and assign a unique PlayerPrefs string name. If the timer was counting down/up and the app is closed or the scene is changed, when the scene is reopened by the app again, it will continue from its last value (where it left off, instead of starting over).







    3D/UI Analog Clock Prefabs:
    • 3D/UI clock with second, minute, and hour hand objects
    • Use your own meshes/sprites
    • Display the system time or a timer components time
    • System time hour offset - allows simulation of timezones for different clocks





    3D/UI Analog Stopwatch Prefabs:
    • 3D/UI clock with second and minute hand objects attached to separate faces
    • Use your own meshes/sprites
    • Display a timer components time






     
    Last edited: Dec 5, 2022
  2. alahti

    alahti

    Joined:
    Feb 7, 2013
    Posts:
    4
    How to make it run infinity?
     
  3. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    I'll add that in as an option.
     
    Last edited: Oct 30, 2015
  4. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    -Timer Type can now be set to count up infinite to only display a time rather than promoting the user with a times up interface.

    -Additional variables were made public to allow referencing these values for other purposes in your project from other scripts or for various reasons. If you want to create your own custom way of displaying the time variables when counting up you can now reference the following variables from this component:
    *millisecond
    *second
    *minute
    *hour
    *day

    -It's now possible to adjust the timeScale to make time move faster as well as the timer speed to make only the timer move faster through the inspector.
     
    Last edited: Feb 26, 2016
  5. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.03 is now available.
     
  6. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    New feature requests have been added for version 1.04. Submitted today. Also added a 4.6.7 package for Unity 4 users.

    1. Timer moved to GameObject/UI/Timer Menu, you can now right click to add UI/Timer . Additionally, the canvas and event system objects are only added to the scene if they're not currently there, similar to standard UI components.​

    2. Only display the fields you want in the timer text string available options are minutes, seconds, milliseconds for timer count up/down. When the timer counts up infinitely you can choose to display days, hours, minutes, seconds, milliseconds.

    3. Custom callback function using "UnityEvent" added to inspector to design your own times up configuration, easily call custom functions from other objects.

    4. Timescale can now optionally be set to 0 on times up.

    5. Methods have been added to control the timer from your other scripts, you can now make a reference to the timer and call the following:

    GetTimerValue() returns the unformatted float value used for timer.
    RestartTimer() resets the timer.
    StopTimer() pause or stop the timer.
    StartTimer() starts the timer.
     
    Last edited: Dec 9, 2015
  7. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    To make this asset work with Text Mesh Pro all you need to do is replace the word "Text" with "TMPro.TextMeshProUGUI" or "TMPro.TextMeshPro" (depends which type of TMP text you will use) for the "timerText" variable on line 29 of update, do this in the STK_Timer script.

    I've tried very hard but could not find a way to make a generic object field to automate this. I was able to generate the proper references through reflection and file checking but the object remained a generic object type rather than inherit the TMPro.TextMeshProUGUI type I was trying to manually assign through code. Because TMP uses its own namespace, I'm unable to access the text field in an automated or generic way. If I'm able to find a new trick to get around the namespcae issue for public variables I will automate this.
     
  8. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.04 now available.
     
  9. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    1.05 will be submitted today. Added 3D analog clock prefab.
     
    Last edited: Dec 30, 2015
  10. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    A uGUI analogue clock will also be included
     
    Last edited: Dec 30, 2015
  11. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.05 is now available.
     
  12. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Timer 1.051 submitted.
    -Added ability to optionally display system time instead of a generic game time when the timer is set to count up infinitely. This can be used for the timer string, uGUI analog clock or 3D analog clock to display real world time.
    -Added PlayMaker support with Actions for Start, Stop, Restart, and Reset.
     
    Last edited: Mar 28, 2017
  13. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    1.051 will also include PlayMaker action support for Start, Stop, Restart and Reset functions. You can download the PlayMaker add-on package from the link in this forums description, at the top of this page.
     
    Last edited: Feb 3, 2016
  14. Gatskop_Software

    Gatskop_Software

    Joined:
    Sep 21, 2014
    Posts:
    86
    Getting this when import to unity 5.1.3f3 playmaker actions
    Assets/PlayMaker/Actions/Timer/TimerReset.cs(17,31): error CS1061: Type `STK_Timer' does not contain a definition for `ResetTimer' and no extension method `ResetTimer' of type `STK_Timer' could be found (are you missing a using directive or an assembly reference?)
     
  15. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Email me your invoice number and I'll send you the 1.051 update, or you can wait for it to be approved. I changed the public methods a bit for the actions.You can also delete the script with errors and others should work fine.
     
  16. Gatskop_Software

    Gatskop_Software

    Joined:
    Sep 21, 2014
    Posts:
    86
    I did mail you thanks
     
  17. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    You're welcome, let me know if you need more or need any adjustments.
     
  18. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    version 1.051 is now available.
     
  19. warpvr

    warpvr

    Joined:
    Dec 17, 2014
    Posts:
    14
    Looks like a great asset!

    Does the asset also work for iOS and Android? And is it possible to count up and to add actions at certain times (also if the time is not up yet?). And can the time continue to count whilst the time is up?
     
  20. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Thanks, I currently don't have any Apple hardware to test on, but I've used this asset many times on Android.

    If you're scripting, you can reference the timer like any other component in your scripts once the timer is in your scene to control it. With the public methods Start,Stop,Restart, Reset and create your own custom actions that you can pass into the component when needed. The UI will always display the timers current value.

    Currently the timer by default will only call an event when time's up. I do plan on adding multiple time based events some time in the near future.

    I will make a bool to let the timer continue counting up when the time's up for the next update, it currently will not count when the time limit is reached unless it's reset.
     
  21. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.052 has been submitted submitted.

    -Proper timer spawning respect for selected canvases or an unselected canvas in scene.
    -Removal of generic menu window from timer prefab.
    -Multiple timers have been tested in a scene and are able to operate correctly without disruption of others.
     
  22. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.052 is now available.
     
  23. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.053 submitted.

    -Added PDF Overview

    NOTE: PDF overview is also available for download here
     
  24. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Just bought and downloaded the most recent version.
    Assets/TurnTheGameOn/Timer/Scripts/STK_Timer.cs(167,61): warning CS0618: `UnityEngine.Application.LoadLevel(string)' is obsolete: `Use SceneManager.LoadScene'
     
  25. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510

    I'll add some platform dependent compilation in next update so we won't see that warning in newer versions of Unity.
     
  26. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Version 1.054 submitted.
    • Set default values for some variables to make the timer easier to use when working with the script only, as opposed to using the prefab.
    • Added version specific compilation to remove console warnings.
    • Removed Timer Prefix; this is trivial to add to a scene if needed.
     
  27. hanso23

    hanso23

    Joined:
    Jul 22, 2012
    Posts:
    16
    Hey @TurnTheGameOn !
    I've got a little question concerning the asset before buying - is it possible to pause a timer (and continue after a event happend?). I'm using mainly playmaker to create all my game-logic and this would be a super handy asset ;)
     
    Stephen_O likes this.
  28. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hello, yes this is possible. You can use the timer's event to pause the timer at a given time, make any necessary event calls then have the timer resume after the events are completed. The timer methods and variables are all public so you can access them from other scripts and tools like Playmaker. You can also string multiple timers together to create a more complex timing system and have the timers control each other if desired.
     
    hanso23 likes this.
  29. Bobby_F

    Bobby_F

    Joined:
    May 24, 2011
    Posts:
    9
    Hi there,

    Is it possible to use this asset to create an alarm clock?

    One that will let us set a time in the app, and then have the app 'awaken' and play a sound effect?

    Thanks in advance.

    Bobby
     
    Stephen_O likes this.
  30. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hi, you can hookup events to be called when times up and set the timer to count up/down from any value.

    For your case you would need to have a script that can send the notification to the device and a script to do any other event handling in the scene; you can hook those methods up to the times up event, You would also need to write a UI and create the logic to change the timer settings for your scenario.
     
  31. hanso23

    hanso23

    Joined:
    Jul 22, 2012
    Posts:
    16
    Hey!

    I'm sorry for my late reply, I didn't see a notification! Thanks for anwser, perfect, that's exactly what I'm looking for! I'll definitely check out your asset in the next days! cheers!
     
  32. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    No problem, I'm happy to answer even if you don't buy... and you're welcome, let me know if you have any more questions.
     
  33. a1laserboy

    a1laserboy

    Joined:
    Nov 15, 2015
    Posts:
    2
    Hi just got this, works great!

    I'm not very experienced in unity yet, but managed to add countdown timers into my scenes to jump to another with no problem, struggled for ages before finding this.

    I have another use and hope you can help me out. I need to build a race timer (for a physical game) so I need to start a stopwatch with a button and have 4 buttons to log the 4 finishers times as they cross the line. I downloaded the add on bundle (windows 10, Unity 5.5.0f3) and just got a bunch of errors on import in the console.

    Sorry for such a newb question.

    Cheers :)
     
  34. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hello, that's great I'm glad you were able to accomplish something that was more difficult before this!

    You should be able to make your stopwatch using only the timer component included in the asset. You can create UI buttons in your scene and 1 (or 4 timers, depending on how you want to structure your scene logic), hook each button up to the timer to control when it will start, stop, or log a finish time.
     
    Last edited: Jul 24, 2020
  35. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    Hey there! How would you add time to a timer during runtime?

    thanks!
     
    Stephen_O likes this.
  36. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Hey, good question! That variable's currently private but it should be public for that reason. I'll make sure to update it soon. For now please edit the Timer.cs script line 33, change private to public. Then you can do something like this:
    Code (CSharp):
    1.  
    2. public TurnTheGameOn.Timer.Timer timer;
    3.  
    4. public void IncreaseTimerValue () {
    5.     timer.gameTime += 10.0f;
    6. }
     
  37. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    thanks!
     
    Stephen_O likes this.
  38. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    So I've got a tiny little issue. When I stop the timer and add time to it the new time isn't reflected in the UI until the timer is restarted.

    I'm currently using a coroutine to quickly stop/start/stop the timer.

    But could there be a better way?
    Cheers!
     
    Stephen_O likes this.
  39. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    For now you can add the following line the first line of the Update method and it will allow the timer to be updated even while it's not counting.
    Code (CSharp):
    1. if (timerText != null) timerText.text = FormatSeconds(gameTime);
    Next update I will be sure to add a public method so you can do this easier and have more control.
     
    brettboring likes this.
  40. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    You're a champ! thanks for the quick responses.
     
    Stephen_O likes this.
  41. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    How would i display seconds as a single digit? ie 1,2,3.. instead of 01,02,03

    Also do you have plans to comment the code at any stage :)
    ta!
     
    Stephen_O likes this.
  42. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    As a quick solution you can add this line after line 79 in the Timer.cs script:
    Code (CSharp):
    1. if (t.Seconds < 10 && s == "{2:D2}") s = "{2:D1}";
    I'll submit an update with this option added as a toggle to the inspector for timer seconds, minutes and hours.

    I can try to work on commenting the code a bit too :)
     
  43. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    Thanks!
    Unfortunately that code didn't work for me but I was able to see where and how to change it in CheckTimerOptions() and use a bool to achieve what i needed.

    Code (CSharp):
    1. if (timerFormat.seconds) {
    2.                 s = "{2:D2}";
    3.                 if (CTimer) {
    4.                     s = "{2:D1}";
    5.                 }
    6.             } else {
    7.                 s = "";
    8.             }
    Not perfect but my level timer will never be below 10 seconds if CTimer is true :p
     
    Stephen_O likes this.
  44. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    Timers and Clocks v1.09 has been submitted.

    •Added leading zero toggle option for timer second, minute and hour values.
    •Added logic to allow the timer's UI string to be updated while it's not counting so it can reflect changes made.
     
    Last edited: Jun 20, 2019
    brettboring likes this.
  45. a1laserboy

    a1laserboy

    Joined:
    Nov 15, 2015
    Posts:
    2
    I have another dumb question... Is there a way to time out user inactivity at all? Maybe time since last keypress, time since touch, mouse click, or mouse move? I suppose 'any' user input?

    cheers
     
  46. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    This forum question is pretty much the same as yours: http://answers.unity3d.com/questions/18834/does-unity-provide-a-means-to-determine-the-time-s.html

    The proposed solution is to use
    Code (CSharp):
    1. Input.anyKey
    to detect the input, then add a bool as a flag to mark it. You can hook a timer reset into that the input detection and have the timer always count up. Every time input is received the timer would reset, you can use this timer as a timeout timer if it reaches your target value call your timeout function.
     
  47. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    hmm i'm trying to display a timers gameTime value through another text component but i'm having trouble formatting in script to display as 0.0 instead of 0.0000. any tips?
     
  48. Stephen_O

    Stephen_O

    Joined:
    Jun 8, 2013
    Posts:
    1,510
    You can do this
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using TurnTheGameOn.Timer;
    4.  
    5. public class test : MonoBehaviour {
    6.  
    7.     public Timer timer;
    8.     public Text textReference;
    9.  
    10.     void Update () {
    11.         textReference.text = timer.gameTime.ToString ("F1");
    12.     }
    13.  
    14. }
    You can change the 1 to another value to control the number of points displayed.
     
  49. brettboring

    brettboring

    Joined:
    Nov 8, 2013
    Posts:
    33
    thanks! had to add GetTimerValue() before ToString to get it to work.
     
  50. hanso23

    hanso23

    Joined:
    Jul 22, 2012
    Posts:
    16
    Hey!

    I bought your wonderful asset in the meantime and it's working perfectly with my playmaker setup :) But I've got one more little question - I'm building a game where the timer-asset is used to limit the main playtime, counting down 5 minutes. I would like to incude an option where a certain event would cause a subtraction of x-seconds from the running timer. For example a "trigger enter" - event => -5 seconds of the running "main gameplay time". Is something like this possible or maybe there is already an option which I have overlooked?
     
    Stephen_O likes this.