Quick Start Guide
The RetroDev.Timer class provides a flexible and customizable timer functionality for Unity game development. It allows you to create timers with specific durations and attach callback functions to various events such as timer start, stop, pause, resume, and completion.
Example Usage
1. Creating a Timer and Starting it:
// Create a new timer with a duration of 10 secondsGameTimer timer = new GameTimer(10f);
// Start the timertimer.Start();2. Pausing and Resuming a Timer:
// Pause the timertimer.Pause();
// Resume the timertimer.Resume();3. Stopping and Resetting a Timer:
// Stop the timertimer.Stop();
// Reset the timertimer.Reset();4. Checking Timer Status:
// Check if the timer is runningbool isRunning = timer.IsRunning();
// Check if the timer is pausedbool isPaused = timer.IsPaused();5. Handling Timer Events:
// Attach callback functions to timer eventstimer.onStartCallback += () => Debug.Log("Timer started!");timer.onStopCallback += () => Debug.Log("Timer stopped!");timer.onPauseCallback += () => Debug.Log("Timer paused!");timer.onResumeCallback += () => Debug.Log("Timer resumed!");timer.onTimerCompleteCallback += () => Debug.Log("Timer completed!");Remarks
- Ensure that you call the
Update()method of theGameTimerinstance in theUpdate()method of a MonoBehaviour to update the timer’s internal state. - You can attach callback functions to respond to timer events such as start, stop, pause, resume, and completion by using delegate assignment (
+=) syntax. - The timer automatically stops when its duration is reached, and the associated completion callback is invoked.
- Use the
GetElapsedTime()andGetDuration()methods to retrieve the current elapsed time and total duration of the timer, respectively.
Getting Help
Don’t hesitate to reach out if you need help:
- Email: [email protected]
- Social: Find me on GitHub, Twitter, or any of the platforms linked in the header
I built these tools to help developers, so please use me as a resource. Questions, bug reports, feature requests—I want to hear all of it.