Skip to content

Quick Start Guide

The Eidolon.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 seconds
GameTimer timer = new GameTimer(10f);
// Start the timer
timer.Start();

2. Pausing and Resuming a Timer:

// Pause the timer
timer.Pause();
// Resume the timer
timer.Resume();

3. Stopping and Resetting a Timer:

// Stop the timer
timer.Stop();
// Reset the timer
timer.Reset();

4. Checking Timer Status:

// Check if the timer is running
bool isRunning = timer.IsRunning();
// Check if the timer is paused
bool isPaused = timer.IsPaused();

5. Handling Timer Events:

// Attach callback functions to timer events
timer.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 the GameTimer instance in the Update() 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() and GetDuration() methods to retrieve the current elapsed time and total duration of the timer, respectively.