Logo
UI Elements

Timer

A flexible timer with animations

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

NameTypeDescription
durationfloatTotal time in seconds
currentTimefloatCurrent raw timer value
textFormatstringFormat containing 0 placeholder
displayFormatDisplayFormatControls numeric or time display
isRunningboolTrue while timer is active
isCompletedboolTrue when timer completes

Settings

NameTypeDescription
autoStartboolStarts timer automatically on Start
countDownboolCounts down when true, up when false
loopboolRestarts timer after completion
isVerticalboolUses vertical fill direction

Animation

NameTypeDescription
enableSmoothingboolAnimates fill and text values
updateBarOnSecondsOnlyboolUpdates bar only when whole seconds change
smoothingDurationfloatAnimation duration

References

NameTypeDescription
fillRectRectTransformFill anchor or Image fill target
valueTextTMP_TextDisplays formatted time

Events

NameTypeDescription
onValueChangedTimerEventFired whenever display value changes
onTimerCompleteUnityEventFired when reaching zero or duration
onTimerStartUnityEventFired when starting timer
onTimerStopUnityEventFired when stopping timer
onTimerResetUnityEventFired when timer resets

Public Methods

NameParametersDescription
StartTimer()NoneStarts timer
StopTimer()NoneStops timer
PauseTimer()NoneStops counting without events
ResumeTimer()NoneContinues counting
ResetTimer()NoneResets currentTime and display
SetCurrentTime(value)floatSets time and triggers events
SetCurrentTimeWithoutNotify(value)floatSets time without events
AddTime(value)floatAdds time
SubtractTime(value)floatRemoves time
GetRemainingTime()NoneReturns remaining time
GetElapsedTime()NoneReturns elapsed time

Code Example

TimerExample.cs
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();
    }
}

On this page