Timer Overview
What is RetroDev.Timer?
RetroDev.Timer is a flexible, event-driven timer system for Unity. It provides a clean, reusable timer class with callback support, making it easy to handle time-based gameplay mechanics without cluttering your MonoBehaviours with countdown logic.
Get RetroDev.Timer here:
The Problem It Solves
Implementing timers in Unity often leads to messy code scattered across update loops:
Before RetroDev.Timer:
private float timer = 10f;private bool timerRunning = true;private bool timerPaused = false;
void Update() { if (timerRunning && !timerPaused) { timer -= Time.deltaTime; if (timer <= 0) { timer = 0; timerRunning = false; OnTimerComplete(); } }}With RetroDev.Timer:
private GameTimer timer;
void Start() { timer = new GameTimer(10f); timer.onTimerCompleteCallback += OnTimerComplete; timer.Start();}
void Update() { timer.Update();}Key Features
Complete Timer Control
Start, stop, pause, resume and reset with simple method calls. Full control over timer state.
Event-Driven
Attach callbacks for start, stop, pause, resume, and completion events. Your code stays organized and reactive.
Reusable
Create a timer once, reset and reuse it as many times as you need. No need to instantiate new timers constantly.
State Tracking
Query timer state at any time: Is it running? Paused? How much time is left?
What RetroDev.Timer Provides
Timer Control Methods
Start()- Begin countdownStop()- Stop timer completelyPause()- Pause without resettingResume()- Continue from paused stateReset()- Reset to original duration
State Queries
IsRunning()- Check if actively counting downIsPaused()- Check if pausedGetElapsedTime()- Get time that has passedGetDuration()- Get total timer duration
Event Callbacks
onStartCallback- Fires when timer startsonStopCallback- Fires when timer is stoppedonPauseCallback- Fires when timer is pausedonResumeCallback- Fires when timer resumesonTimerCompleteCallback- Fires when countdown reaches zero
Common Use Cases
Cooldown Systems:
private GameTimer abilityCooldown;
void UseAbility() { abilityCooldown = new GameTimer(5f); abilityCooldown.onTimerCompleteCallback += () => { Debug.Log("Ability ready!"); }; abilityCooldown.Start();}Round/Match Timers:
private GameTimer matchTimer;
void StartMatch() { matchTimer = new GameTimer(300f); // 5 minutes matchTimer.onTimerCompleteCallback += EndMatch; matchTimer.Start();}
void Update() { matchTimer.Update(); UpdateUITimer(matchTimer.GetElapsedTime());}Timed Power-Ups:
void ActivatePowerUp() { var powerUpTimer = new GameTimer(10f); powerUpTimer.onStartCallback += () => player.EnablePowerUp(); powerUpTimer.onTimerCompleteCallback += () => player.DisablePowerUp(); powerUpTimer.Start();}Pause Menu Integration:
void PauseGame() { matchTimer.Pause(); enemySpawnTimer.Pause(); bonusTimer.Pause();}
void ResumeGame() { matchTimer.Resume(); enemySpawnTimer.Resume(); bonusTimer.Resume();}When to Use RetroDev.Timer
Perfect for:
- Ability cooldowns
- Match/round timers
- Power-up durations
- Respawn timers
- Wave/spawn intervals
- Any time-based game mechanic
You might not need it if:
- You’re using a coroutine-based approach
- You only need a single simple countdown
- You prefer Unity’s built-in Invoke methods
Important Notes
void Update() { timer.Update(); // Don't forget this!}Multiple Timers
You can manage multiple timers easily:
private GameTimer attackCooldown;private GameTimer specialCooldown;private GameTimer healthRegen;
void Update() { attackCooldown.Update(); specialCooldown.Update(); healthRegen.Update();}Getting Started
Ready to add clean timer functionality to your game? Check out the Quick Start guide for complete examples and best practices.