Logo
UI Elements

Counter

A smooth animated number counter

Overview

Counter displays a numeric value with optional prefixes, formatting styles, and animated transitions. It's ideal for currency displays, score counters, or statistics.


Usage

Add Counter to a TextMeshProUGUI object

Set a starting value

Choose a number Display Format

Optionally define a Text Format such as "$ {0}" or "Score: {0}"

Use SetValue, AddToValue, or SubtractFromValue to update the counter programmatically


Properties

Value Settings

NameTypeDescription
valuefloatTarget value displayed or animated toward
textFormatstringPrefix or suffix format containing {0} placeholder
displayFormatDisplayFormatFormatting type (fixed decimals or thousands grouped)

Animation Settings

NameTypeDescription
animateOnEnableboolAnimates to target value when enabled
useUnscaledTimeboolUses unscaled delta time for animation
counterDurationfloatDuration of value interpolation
delayfloatDelay before animation begins
animationCurveAnimationCurveCurve used for easing

References

NameTypeDescription
textObjectTextMeshProUGUIThe text component displaying the number

Public Methods

NameParametersDescription
SetValue(newValue)floatSets new target value and animates toward it
SetValue(newValue)intInteger overload
SetValueInstant(newValue)floatImmediately updates value without animation
SetValueInstant(newValue)intInteger overload
AddToValue(amount)floatAdds to target value and animates
SubtractFromValue(amount)floatSubtracts from target value and animates
GetFormatString()NoneReturns internal numeric format string (F or N type)

Code Example

CounterExample.cs
using UnityEngine;
using Evo.UI;

public class CounterExample : MonoBehaviour
{
    public Counter counter;

    void Start()
    {
        // Set instant value
        counter.SetValueInstant(100);

        // Animate to 500
        counter.SetValue(500);

        // Add to value
        counter.AddToValue(250);

        // Subtract from value
        counter.SubtractFromValue(50);

        // Change formatting
        counter.textFormat = "$ {0}";
        counter.displayFormat = Counter.DisplayFormat.Number1;

        // Snap directly to a new value
        counter.SetValueInstant(9999);
    }
}

On this page