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
| Name | Type | Description |
|---|---|---|
value | float | Target value displayed or animated toward |
textFormat | string | Prefix or suffix format containing {0} placeholder |
displayFormat | DisplayFormat | Formatting type (fixed decimals or thousands grouped) |
Animation Settings
| Name | Type | Description |
|---|---|---|
animateOnEnable | bool | Animates to target value when enabled |
useUnscaledTime | bool | Uses unscaled delta time for animation |
counterDuration | float | Duration of value interpolation |
delay | float | Delay before animation begins |
animationCurve | AnimationCurve | Curve used for easing |
References
| Name | Type | Description |
|---|---|---|
textObject | TextMeshProUGUI | The text component displaying the number |
Public Methods
| Name | Parameters | Description |
|---|---|---|
SetValue(newValue) | float | Sets new target value and animates toward it |
SetValue(newValue) | int | Integer overload |
SetValueInstant(newValue) | float | Immediately updates value without animation |
SetValueInstant(newValue) | int | Integer overload |
AddToValue(amount) | float | Adds to target value and animates |
SubtractFromValue(amount) | float | Subtracts from target value and animates |
GetFormatString() | None | Returns internal numeric format string (F or N type) |
Code Example
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);
}
}