Skip to content

GabrielBigardi/Unity-Simple-Timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⏱️ Simple Timer System for Unity

A lightweight and easy-to-use timer system for Unity, designed with flexibility, performance, and simplicity in mind. Automatically managed and lifecycle-safe, ideal for gameplay logic, delays, cooldowns, and more.

Demo

✨ Features

  • ⏳ Create simple or looping timers
  • ✅ Automatically managed by TimerManager
  • 🧰 A custom inspector on TimerManager for debugging purposes
  • 🔁 Loop support with customizable amount
  • 🛑 Pause and resume support
  • 🧠 Callback events for:
    • Tick updates
    • Timer completion
    • Cycle/loop transitions
    • Pause/resume/kill lifecycle

📦 Installation

  1. Clone or download and unzip the folder into your Unity project.
  2. Done! TimerManager will automatically bootstrap on game start.

🧩 Usage Example

new Timer(5f, "MyTimer")
    .SetOnTimerTick(() => Debug.Log("Tick..."))
    .SetOnTimerFinish(() => Debug.Log("Timer finished!"))
    .SetLooping(3); // Optional: loops 3 times

🧠 How It Works

  • TimerManager runs automatically (via [RuntimeInitializeOnLoadMethod]) and updates all active timers every frame.
  • Timers are automatically removed once they are finished or killed.
  • You can pause, resume, or kill any timer at any time.

🔌 API Reference

Timer

Property / Method Description
IsPaused Whether the timer is currently paused
IsFinished Whether the timer has been finished
RemainingSeconds Time remaining in the current cycle
TotalDuration Total time for one cycle
LoopAmount How many times to loop (-1 = infinite)
Tick(float deltaTime) Advance the timer by deltaTime
Pause() / Resume() Pause or resume the timer
Finish() / Kill() Complete or force remove the timer

Fluent Callbacks

SetOnTimerTick(Action)          // Called every tick
SetOnTimerFinish(Action)        // Called when timer completes
SetOnTimerLoop(Action)          // Called when a loop starts
SetOnTimerCycleEnd(Action)      // Called when a cycle ends
SetOnTimerPause(Action)         // Called on pause
SetOnTimerResume(Action)        // Called on resume
SetOnTimerKill(Action)          // Called on manual kill
SetLooping(int loopAmount = -1) // Set loop count (-1 = infinite)

🛠 Internals

TimerManager

  • Keeps a list of active timers.
  • Automatically updates them every frame.
  • Removes completed or killed timers.
public IReadOnlyList<Timer> Timers { get; }

🧪 Example Use Case

void Start()
{
    var myTimer = new Timer(3f)
        .SetOnTimerTick(() => Debug.Log("Ticking"))
        .SetOnTimerFinish(() => Debug.Log("Boom!"));
}

🧾 License

MIT License — see LICENSE for full terms.

👤 Author

Gabriel Bigardi
Game developer and tools programmer

Discord: gabrielbigardi
Twitter: @BigardiGabriel
Email: gabrielbigardi@hotmail.com

About

A simple yet powerful timer system for Unity.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages