Logo
UI Elements

Timer

Countdowns, elapsed time, and a local clock with animated digits

Overview

Timer displays a countdown, a count-up timer, or the local time of day. It can drive a progress fill and animate changing digits.

Preview

Usage

Create a Timer and assign its optional value text and fill.

Set Duration, choose Count Down, and select the time format.

Call ResetTimer() to initialize the starting value, then StartTimer(), or enable Auto Start.


Customization

Display and Fill

Use Enable Rolling for rolling whole-second digits. Decimal places update immediately. Invert Fill reverses only the visible fill. A Procedural Shape’s clipping settings determine the fill direction.

The value text can use any text provider. Use Uniform Digit Width stops changing digits from shifting the time. With TextMesh Pro, it requires Rich Text on the text, and Digit Width Scale adjusts the measured digit width. UniText uses the font's tabular figures instead.

Local System Clock

Enable Use System Clock to display the local time of day. In this mode the fill represents a 24-hour day; duration, count direction, speed, and looping are ignored. This mode is a clock display, not a countdown to a target date.


Notes

PauseTimer() pauses without firing onTimerStop; StopTimer() invokes that event. Normal completion invokes onTimerComplete, not onTimerStop. Set Use Unscaled Time when the timer must keep running at Time.timeScale = 0.


Public API

Use Timer in the Evo.UI namespace.

Properties

NameTypeDescription
IsRunningboolRead-only running state.
IsCompletedboolRead-only completion state.
UseUniformDigitWidthboolGives every digit the same width so the time never shifts.

Fields

NameTypeDescription
durationfloatCountdown/count-up duration in seconds.
currentTimefloatCurrent seconds; elapsed since midnight in clock mode.
countDownboolCounts toward zero when enabled.
useSystemClockboolDisplays local time instead of a duration timer.
useUnscaledTimeboolIgnores the gameplay time scale.
enableRollingboolAnimates whole-second digit changes.
invertFillboolReverses the fill without changing time.

Methods

NameParametersDescription
StartTimer()NoneStarts a timer that is not already running.
PauseTimer()NonePauses time progression.
ResumeTimer()NoneResumes a paused timer.
StopTimer()NoneStops and invokes the stop event.
ResetTimer()NoneRestores the starting time or refreshes the clock.
SetCurrentTime()float newTimeSets seconds and notifies listeners.
SetCurrentTimeWithoutNotify()float newTimeSets seconds without the value event.
AddTime()float timeToAddAdds seconds to currentTime.
SubtractTime()float timeToSubtractSubtracts seconds from currentTime.
GetRemainingTime()NoneReturns remaining seconds in the time range. Returns float.
GetElapsedTime()NoneReturns elapsed seconds in the time range. Returns float.

Events

NameTypeDescription
onValueChangedUnityEvent<float>Invoked with current seconds.
onTimerCompleteUnityEventInvoked on reaching the end, before a loop restarts.
onTimerStartUnityEventInvoked when StartTimer starts a stopped timer.
onTimerStopUnityEventInvoked by StopTimer.
onTimerResetUnityEventInvoked after reset.

Example

TimerExample.cs
using UnityEngine;
using Evo.UI;

public class TimerExample : MonoBehaviour
{
    [SerializeField] private Timer target;

    private void Start()
    {
        target.useSystemClock = false;
        target.duration = 60f;
        target.countDown = true;
        target.enableRolling = true;
        target.ResetTimer();
        target.onTimerComplete.AddListener(() => Debug.Log("Time is up"));
        target.StartTimer();
    }
}

On this page