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:
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.