Skip to main content
The Timer class lets you measure and control the passage of time inside a script. You start a timer with a duration in seconds, optionally attach finish and tick callbacks, and then check its state each frame. Timers are ideal for enforcing cooldowns, delaying actions, and scheduling periodic events without blocking script execution. A single Timer instance can be started, stopped, and restarted as many times as you need, making it easy to reuse the same object across multiple cooldown cycles.

Constructors

Timer is instantiated with the global new helper:
No arguments are required at construction time. You call start to actually begin counting.

Instance Properties


Instance Methods

start

Starts the timer. You can provide optional callbacks and an optional initial elapsed time.

stop

Stops the timer. Optionally fires the onFinish callback even though the timer did not reach zero naturally.

addTime

Adds seconds to the remaining time. Optionally expands maxTime if the addition would push remaining time above the current maximum.

subtractTime

Subtracts seconds from the remaining time. This can trigger the finish callback if remaining time drops to zero or below.

Usage Examples

Cooldown using OnUpdate

The pattern below fires a projectile immediately on the first call, then waits 2 seconds before allowing another shot.

One-shot delayed action with a finish callback

Counting down with a per-tick callback

Extending a running timer