Evo uiUi elements
Timer
A flexible timer with animations
This page documents Evo UI v1. For the current version, see Evo UI v2. Upgrading? Read the migration guide.
Overview
Timer provides a complete time counting system that is designed for gameplay timers, cooldowns, crafting bars, progress displays, challenge timers, and any UI that needs time tracking.
When smoothing is enabled, the visual bar and text animate toward the target time value.
Properties
Timer
| Name | Type | Description |
|---|---|---|
duration | float | Total time in seconds |
currentTime | float | Current raw timer value |
textFormat | string | Format containing 0 placeholder |
displayFormat | DisplayFormat | Controls numeric or time display |
isRunning | bool | True while timer is active |
isCompleted | bool | True when timer completes |
Settings
| Name | Type | Description |
|---|---|---|
autoStart | bool | Starts timer automatically on Start |
countDown | bool | Counts down when true, up when false |
loop | bool | Restarts timer after completion |
isVertical | bool | Uses vertical fill direction |
Animation
| Name | Type | Description |
|---|---|---|
enableSmoothing | bool | Animates fill and text values |
updateBarOnSecondsOnly | bool | Updates bar only when whole seconds change |
smoothingDuration | float | Animation duration |
References
| Name | Type | Description |
|---|---|---|
fillRect | RectTransform | Fill anchor or Image fill target |
valueText | TMP_Text | Displays formatted time |
Events
| Name | Type | Description |
|---|---|---|
onValueChanged | TimerEvent | Fired whenever display value changes |
onTimerComplete | UnityEvent | Fired when reaching zero or duration |
onTimerStart | UnityEvent | Fired when starting timer |
onTimerStop | UnityEvent | Fired when stopping timer |
onTimerReset | UnityEvent | Fired when timer resets |
Public Methods
| Name | Parameters | Description |
|---|---|---|
StartTimer() | None | Starts timer |
StopTimer() | None | Stops timer |
PauseTimer() | None | Stops counting without events |
ResumeTimer() | None | Continues counting |
ResetTimer() | None | Resets currentTime and display |
SetCurrentTime(value) | float | Sets time and triggers events |
SetCurrentTimeWithoutNotify(value) | float | Sets time without events |
AddTime(value) | float | Adds time |
SubtractTime(value) | float | Removes time |
GetRemainingTime() | None | Returns remaining time |
GetElapsedTime() | None | Returns elapsed time |
Code Example
using UnityEngine;
using Evo.UI;
public class TimerExample : MonoBehaviour
{
public Timer timer;
void Start()
{
// 60 second countdown
timer.duration = 60f;
timer.currentTime = 60f;
timer.countDown = true;
timer.enableSmoothing = true;
timer.textFormat = "{0}";
timer.displayFormat = Timer.DisplayFormat.Time_MM_SS;
// Listen to events
timer.onValueChanged.AddListener(v =>
{
Debug.Log("Time: " + v);
});
timer.onTimerComplete.AddListener(() =>
{
Debug.Log("Timer finished");
});
// Start the timer
timer.StartTimer();
}
void Update()
{
// Manual controls
if (Input.GetKeyDown(KeyCode.R))
timer.ResetTimer();
if (Input.GetKeyDown(KeyCode.Space))
timer.StopTimer();
}
}