Scripting Support (C#)

advanced scripting

Digits FX · Scripting Support (C#)

Class: All members on this page belong to the Digits base class. Use Digits3D for 3D world-space or DigitsUI for UI Canvas. Access via GetComponent<Digits3D>() or GetComponent<DigitsUI>().
Tip: Check the demo scene scripts for runtime usage examples.

Getting Started

Add using DigitsFX; at the top of your script. Use Digits3D for 3D world-space displays and DigitsUI for UI Canvas displays. Both inherit from the Digits base class.

using DigitsFX;

// UI display
DigitsUI digits = GetComponent<DigitsUI>();
digits.value = 1234.56;
digits.AnimateTo(9999, duration: 2f);
Important: When changing visual effect properties on the profile at runtime (e.g. profile.tremble, profile.glow, profile.shadow, etc.), call UpdateMaterialProperties() afterwards to apply the changes:
var p = digits.profile;
p.tremble = true;
p.glow = true;
digits.UpdateMaterialProperties();
This is required because these effects are shader-based. Properties like value or animationDuration do not require this call.

Digits (Base Class)

Properties

double value { get; set; }
double animationTargetValue
ProgressBarSource progressBarSource

Source for progress bar value: DigitsValue or UserDefined. Default: DigitsValue.

double progressBarMinValue

Minimum value for progress bar range mapping.

double progressBarMaxValue

Maximum value for progress bar range mapping. Default: 100.

float progressBarProgress

Direct progress bar value (0–1) when progressBarSource is UserDefined. Default: 0.5.

Target value for the current animation.

AutoplayType autoplay

Autoplay mode triggered on enable: defines how the animation starts automatically.

CounterDirection counterDirection

Direction for counter animations: Up or Down. Default: Up.

AnimationDurationScope animationDurationScope

How animation duration is applied: PerStep (duration per digit change) or EntireAnimation (total duration). Default: PerStep.

Current displayed numeric value. Setting this directly updates the display without animation.

bool isAnimating { get; }

Whether an animation is currently playing.

DigitsProfile profile { get; set; }

Per-instance profile. Automatically clones the shared profile for safe per-object customization.

DigitsProfile sharedProfile { get; set; }

Direct reference to the shared profile asset. Changes affect all objects sharing this profile.

bool showValue

Controls visibility of the digit display.

bool showProgressBar

Enable the progress bar display.

float progressBarValue { get; set; }

Get or set the progress bar value directly (0–1).

float globalAlpha

Global alpha/opacity of the entire display (0–1).

float animationDuration

Default animation duration in seconds.

static bool useUnscaledTime

Toggle between scaled and unscaled time for all Digits instances.

Events

DigitsEvent onAnimationStart(Digits digits)

Triggers when an animation starts. Callback receives the Digits instance.

DigitsEvent onAnimationStep(Digits digits)

Triggers at each animation step (per integer change).

DigitsEvent onAnimationStop(Digits digits)

Triggers when the animation completes.

Methods

void AnimateTo(double newNumber, float duration = -1, AnimationDurationScope durationScope = PerStep)
void TriggerVanishOnStep(float? duration = null)

Trigger a vanish effect on each animation step. Pass null to use the profile default duration.

void UpdateMaterialProperties()

Updates all material properties. Call after changing visual settings via script.

static float GetTime()

Returns the current time value used by all Digits instances, respecting the useUnscaledTime setting.

Animate the digits to a new value with optional custom duration.

newNumber
Target value to animate to.
duration
Animation duration (-1 = use default).
durationScope
PerStep (duration per digit change) or EntireAnimation (total duration).
void Add(double amount, float duration = -1, AnimationDurationScope durationScope = PerStep)

Add a value to the current display and animate the change.

void Subtract(double amount, float duration = -1, AnimationDurationScope durationScope = PerStep)

Subtract a value from the current display and animate the change.

void StartCounter(CounterDirection direction = Up, float duration = -1, AnimationDurationScope durationScope = PerStep)

Start a continuous counter animation that counts up or down.

void Stop(bool withStopNotification = true)

Stop the current animation. Set withStopNotification to false to suppress the onAnimationStop event.

void Play()

Start the autoplay animation based on the current autoplay settings.

void TriggerPulse(bool affectsProgressBar = false, float? pulseDuration = null, ...)

Trigger a pulse/scale effect on the display. All parameters are optional — pass null to use profile defaults.

void TriggerShake(float? intensity = null, float? duration = null)

Trigger a shake effect on the digits.

void TriggerMoveAndScale(float? duration = null, EasingType? easing = null, Vector3? moveAmount = null, ...)

Trigger a move and scale effect. All parameters are optional.

void Refresh(bool forceRebuild = false)

Refresh the display and update material properties. Set forceRebuild to true to force font data extraction.

DigitsProfile

ScriptableObject - Stores display and animation settings. Accessed via Digits.profile or Digits.sharedProfile.

Events

event Action onSettingsChanged()

Raised whenever a profile property is modified at runtime. Subscribe to react to display or format changes.

Digits digits = GetComponent<Digits>();
digits.profile.onSettingsChanged += () => {
    Debug.Log("Digits profile settings changed");
};

Digits3DPool (Static Utility)

Object pooling for efficient Digits3D creation (ideal for floating damage/score numbers).

static Digits3D Create(Vector3 position, Quaternion rotation, Transform parent = null)
static Digits3D Create()

Create or reuse a Digits3D instance from the pool at the default position.

static Digits3D Create(Vector3 position)

Create or reuse a Digits3D instance from the pool at the specified position.

static bool Contains(Digits3D instance)

Check if a Digits3D instance is currently managed by the pool.

Create or reuse a Digits3D instance from the pool.

static void Release(Digits3D instance)

Return a Digits3D instance to the pool for reuse.

static void Warmup(int count)

Pre-create pool instances to avoid allocation during gameplay.

static void ReleaseAll()

Clear the entire pool and destroy all instances.

Key Enums

TransitionEffect
AutoplayType

Autoplay animation mode on enable.

CounterDirection

Up, Down

AnimationDurationScope

PerStep, EntireAnimation

ProgressBarSource

DigitsValue, Manual

Scroll, Morph, Fade, FlipVertical, FlipHorizontal, FlipClock, Pixelate, None.

EasingType

Linear, EaseIn, EaseOut, EaseInOut, EaseInCubic, EaseOutCubic, EaseInOutCubic, EaseInBounce, EaseOutBounce, and more.

ProgressBarType

Horizontal, Vertical, Circular.

Format Strings

The formatString property in the profile supports flexible number formatting:

"0.00" → 123.45  •  "0,000" → 1,234  •  "'SCORE: '00000" → SCORE: 01234  •  "HH:MM:SS" → 01:23:45  •  "0.0%" → 50.0%

Code Examples

using DigitsFX;

// Score counter with animation
DigitsUI score = GetComponent<DigitsUI>();
score.AnimateTo(50000, duration: 3f, AnimationDurationScope.EntireAnimation);

// Listen to animation events
score.onAnimationStep.AddListener((Digits d) => {
    Debug.Log("Current value: " + d.value);
});

// Floating damage number with pooling
Digits3D dmg = Digits3DPool.Create(enemyPos + Vector3.up * 2f);
dmg.profile.color = Color.red;
dmg.profile.formatString = "0";
dmg.profile.moveAndScale = true;
dmg.profile.fadeOutAfterDelay = true;
dmg.profile.selfDestructOnFadeOut = true;
dmg.value = 0;
dmg.AnimateTo(250);

// Health bar with damage indicator
DigitsUI hpBar = GetComponent<DigitsUI>();
hpBar.showProgressBar = true;
hpBar.profile.showProgressBarDamage = true;
hpBar.Subtract(30); // Shows damage segment

// Timer countdown
DigitsUI timer = GetComponent<DigitsUI>();
timer.profile.formatString = "MM:SS";
timer.value = 120; // 2 minutes
timer.StartCounter(CounterDirection.Down, duration: 1f);
Was this page helpful?