# Timers & Clocks

A small collection of drag-and-drop timer and clock prefabs that make displaying time and configuring logic that can trigger a time’s up event quick and easy.

![](/files/-MCu0piz4XAFP-p1usvu)

[Asset Store](https://assetstore.unity.com/packages/tools/level-design/timers-clocks-40516?aid=1011lGiG)\
[Discussion Forum](https://forum.unity.com/threads/timers-clocks.346408/)\
\
\
Timer Prefab:\
• 3 modes: Count-down, Count-up, and Count-up infinite\
• Adjustable speed\
• Display current system 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](https://docs.microsoft.com/en-us/dotnet/api/system.double?view=netframework-4.8) 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 seperate faces\
• Use your own meshes/sprites\
• Display a timer components time


# API

## Timer

| Primary Variables |                                                                             |
| ----------------- | --------------------------------------------------------------------------- |
| timerState        | Controls if the timer is *Counting* or *Disabled.*                          |
| timerType         | Controls if the timer will count-up, count-down, or count-up infinitely.    |
| startTime         | Time the timer will start from.                                             |
| finishTime        | Time the timer will stop at.                                                |
| timerSpeed        | Rate at which the timer adds or subtracts time.                             |
| loop              | Timer will auto restart when complete.                                      |
| useSystemTime     | Timer will run as a clock and output system time.                           |
| timesUpEvent      | A UnityEvent that can trigger custom scripting functions when time is up.   |
| setZeroTimescale  | Sets Time.timescale to 0 when time is up.                                   |
| textType          | Assign a default Unity UI Text or Text Mesh Pro UGUI component.             |
| timerTextDefault  | Assign a UI Text component to output a formatted string.                    |
| timerTextTMPUGUI  | Assign a Text Mesh Pro UGUI component to output a formatted string.         |
| displayOptions    | Toggle specific time value fields in the output string.                     |
| leadingZero       | Toggle the leading zero on specific time value fields in the output string. |

| Time Events | Create a list of custom events, the timer will trigger when the assigned time is reached. |
| ----------- | ----------------------------------------------------------------------------------------- |
| eventName   | The name of the custom time event.                                                        |
| eventTime   | The time the event will be triggered.                                                     |
| timeEvent   | The event that's invoked when the event time is reached.                                  |

| Methods               |                                                                                           |
| --------------------- | ----------------------------------------------------------------------------------------- |
| AddTime(double)       | Adds the value to the timer value, use a negative value to subtract time.                 |
| ClampGameTime         | Clamps the timer value to ensure it does not exceed the max double value of 922337193600. |
| GetTimerValue         | Returns the timer value as a double.                                                      |
| SetTimerValue(double) | Set timer to the value.                                                                   |
| StartTimer            | Sets the timer state to counting.                                                         |
| StopTimer             | Sets the timer state to disabled.                                                         |
| UpdateUIText          | Updates the assigned text component to display the current formatted time string.         |
| ResetTimer            | Sets the timer value to start time.                                                       |
| RestartTimer          | Sets the timer value to start time, and starts the timer if it's not running.             |


# Prefabs


# 3D Analog Clock

Location: Assets\TurnTheGameOn\TimersAndClocks\Prefabs\3D Analog Clock

The 3D Analog Clock prefab can be added to a scene to display system time, or a custom game time if a Timer script reference is assigned.

The prefab uses a standard Unity Cube Primitives that can be replaced with your own objects to customize the visual style. You can also replace the face object with your own.

![](/files/-MCslX_bFO-wlQkZ0Fw-)


# 3D Analog Stopwatch

Location: Assets\TurnTheGameOn\TimersAndClocks\Prefabs\3D Analog Stopwatch

The 3D Analog Stopwatch prefab can be added to a scene to display a custom time for minutes and seconds if a Timer script reference is assigned.

The prefab uses a standard Unity Cube Primitives that can be replaced with your own objects to customize the visual style. You can also replace the face object with your own.

![](/files/-MCt0lMVZFj6gxQ8SWrx)


# Timer

Location: Assets\TurnTheGameOn\TimersAndClocks\Prefabs\Timer

The timer prefab contains a Timer script with many customization options that can be used for various purposes.

The Timer script inspector will only show options that are applicable to the current settings.

![](/files/-MHoetspZY5MJUviLGmI)

| Timer Options   |                                                                          |
| --------------- | ------------------------------------------------------------------------ |
| Timer State     | Controls if the timer is *Counting* or *Disabled.*                       |
| Timer Type      | Controls if the timer will count-up, count-down, or count-up infinitely. |
| Start Time      | Time the timer will start from.                                          |
| Finish Time     | Time the timer will stop.                                                |
| Timer Speed     | Rate at which the timer adds or subtracts time.                          |
| Use System Time | Timer will run as a clock and output system time.                        |

![](/files/-MHofQyFurH1iMZs0gW2)

![](/files/-MHogDT4Bh8MF2-w-_Wj)

![](/files/-MHoiE-WXbG1oX-KthWD)

| Time Events | Create a list of custom events, the timer will trigger when the assigned time is reached. |
| ----------- | ----------------------------------------------------------------------------------------- |
| Event Name  | The name of the custom time event.                                                        |
| Event Time  | The time the event will be triggered.                                                     |
| Time Event  | The event that's invoked when the event time is reached.                                  |

![](/files/-MHohHxIVc2spLBk7Qed)

| **Time's Up Event Options** |                                                                           |
| --------------------------- | ------------------------------------------------------------------------- |
| Set Zero Timescale          | Sets Time.timescale to 0.                                                 |
| Times Up Event              | A UnityEvent that can trigger custom scripting functions when time is up. |

![](/files/-MHohgtK6w-hYpUC5GIL)

| UI Text Output     |                                                                             |
| ------------------ | --------------------------------------------------------------------------- |
| Text Type          | Assign a default Unity UI Text or Text Mesh Pro UGUI component.             |
| Timer Text Default | Assign a UI Text component to output a formatted string.                    |
| Timer Text TMPUGUI | Assign a Text Mesh Pro UGUI component to output a formatted string.         |
| Display Options    | Toggle specific time value fields in the output string.                     |
| Leading Zero       | Toggle the leading zero on specific time value fields in the output string. |

![](/files/-MHoeE3E4edgeXiO8ZjL)


# UI Analog Clock

Location: Assets\TurnTheGameOn\TimersAndClocks\Prefabs\UI Analog Clock

The UI Analog Clock prefab can be added to a Canvas in a scene to display system time, or a custom game time if a Timer script reference is assigned.

The prefab uses a standard Unity Images that can be updates with your own custom sprites to customize the visual style.

![](/files/-MCsx2oPJvy8KS21w9TL)


# UI Analog Stopwatch

Location: Assets\TurnTheGameOn\TimersAndClocks\Prefabs\UI Analog Stopwatch

The UI Analog Stopwatch prefab can be added to a scene to display a custom time for minutes and seconds if a Timer script reference is assigned.

The prefab uses a standard Unity Images that can be updates with your own custom sprites to customize the visual style.

![](/files/-MCt4uxHm3wfTVey_AnC)


# Tutorials


# Clock

{% embed url="<https://youtu.be/fGvRN_SaOTs>" %}


# Stopwatch

{% embed url="<https://www.youtube.com/watch?v=Bm1H6xtKB6A&feature=youtu.be>" %}


# Timer

{% embed url="<https://youtu.be/fJGdw0B7jl8>" %}


