Logo
UI Elements

Countdown

A timer component with animated digit transitions

Overview

Countdown is a fully animated time display that counts down hours, minutes, and seconds with smooth sliding digit transitions.


Properties

Timer

NameTypeDescription
hoursintInitial hour value (0 to 23)
minutesintInitial minute value (0 to 59)
secondsintInitial second value (0 to 59)
separatorstringCharacter used between time sections

Settings

NameTypeDescription
autoStartboolStarts countdown automatically on enable
showHoursboolToggles hour display
showMinutesboolToggles minute display
showSecondsboolToggles second display
useUnscaledTimeboolUses unscaled delta time

Spacing

NameTypeDescription
useDynamicSpacingboolAutomatically distributes digit sizes
separatorSpacingfloatSpacing width between separators (fixed mode)
digitSpacingfloatSpacing between digits (fixed mode)

Animation

NameTypeDescription
animationDurationfloatDuration of digit slide transition
slideDistancefloatVertical distance digits slide during change
animationCurveAnimationCurveCurve used for sliding transitions

Styling

NameTypeDescription
stylingSourceStylingSourceSource for font and color styling
stylerPresetStylerPresetPreset used for styling lookup
fontColorColorMappingColor used for digits
timerFontFontMappingFont used for digits
fontSizefloatSize of the digit text
fontStyleFontStylesFont style flags for TextMeshPro

Events

NameTypeDescription
onTimerCompleteUnityEventFired when countdown reaches zero
onTimeChangedUnityEvent<int, int, int>Fired whenever hour, minute, or second value changes

Public Methods

NameParametersDescription
ResetTimer()NoneResets time and stops countdown
SetTime(newHours, newMinutes, newSeconds)int, int, intUpdates timer values and refreshes display
RefreshDisplay()NoneRebuilds layout and redisplays digits
StartTimer()NoneStarts countdown
PauseTimer()NonePauses countdown
GetCurrentTime()NoneReturns remaining time in seconds
IsRunning()NoneReturns true if the timer is active

Code Example

CountdownExample.cs
using UnityEngine;
using Evo.UI;

public class CountdownExample : MonoBehaviour
{
    public Countdown countdown;

    void Start()
    {
        // Set custom start time
        countdown.SetTime(1, 20, 45);

        // Listen for time changes
        countdown.onTimeChanged.AddListener((h, m, s) =>
        {
            Debug.Log("Time changed: " + h + ":" + m + ":" + s);
        });

        // Listen for completion
        countdown.onTimerComplete.AddListener(() =>
        {
            Debug.Log("Countdown finished");
        });

        // Start the timer
        countdown.StartTimer();

        // Pause or resume
        countdown.PauseTimer();

        // Reset
        countdown.ResetTimer();
    }
}

On this page