This is a simple timer utility for Unity. It allows you to create and control timer objects in your Unity projects.
- Create timer objects with a specified duration
- Start, pause, and reset timers
- Get timer progress and check if timer has ended
- Timer events for start, pause, end etc.
- Different timer modes:
- Continuous
- Instant stop
- Loop
- Easy to use API
Timer myTimer = new Timer();
Set duration and start timer:
myTimer.Begin(10f); // 10 seconds duration
Optionally specify timer mode:
myTimer.Begin(10f, TimerMode.Loop);
myTimer.Play(); // Start or resume
myTimer.Pause(); // Pause
myTimer.Reset(); // Reset
float progress = myTimer.Progress(); // Get progress
if(myTimer.IsEnd()) {
// Timer ended
}
if(myTimer.ReachProgress(5f)) {
// Reached 5 seconds
}
myTimer.TimerStarted += OnTimerStarted;
...
void OnTimerStarted() {
// Do something
}
Call Update()
method on timer instance:
void Update() {
myTimer.Update();
}
Simply include the Timer.cs file in your Unity project.
Pull requests are welcome. Feel free to open issues for any enhancements or bugs.