Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgryu committed May 5, 2016
1 parent b97191c commit 88567aa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ Timer.Register(5f, () => Debug.Log("Hello World"));

### Features

- Make a timer repeat by setting `isLooped` to true.
**Make a timer repeat by setting `isLooped` to true.**

```c#
// Call the player's jump method every two seconds.
Timer.Register(2f, player.Jump, isLooped: true);
```

- Cancel a timer after calling it.
**Cancel a timer after calling it.**

```c#
Timer timer;
Expand All @@ -58,7 +58,7 @@ void Update() {
}
```

- Measure time by [realtimeSinceStartup](http://docs.unity3d.com/ScriptReference/Time-realtimeSinceStartup.html) instead of scaled game time by setting `useRealTime` to true.
**Measure time by [realtimeSinceStartup](http://docs.unity3d.com/ScriptReference/Time-realtimeSinceStartup.html) instead of scaled game time by setting `useRealTime` to true.**

```c#
// Let's say you pause your game by setting the timescale to 0.
Expand All @@ -67,7 +67,7 @@ Time.timeScale = 0f;
// ...Then use real time so this timer will still fire even though the game time isn't progressing.
Timer.Register(1f, this.HandlePausedGameState, useRealTime: true);
```
- Attach the timer to a MonoBehaviour so that the timer is destroyed when the MonoBehaviour is.
**Attach the timer to a MonoBehaviour so that the timer is destroyed when the MonoBehaviour is.**

Very often, a timer called from a MonoBehaviour will manipulate that behaviour's state. Thus, it is common practice to cancel the timer in the OnDestroy method of the MonoBehaviour. We've added a convenient extension method that attaches a Timer to a MonoBehaviour such that it will cancel the timer when the MonoBehaviour is detected as null.

Expand Down Expand Up @@ -95,6 +95,13 @@ public class CoolMonoBehaviour : MonoBehaviour {
}
```

**A number of other useful features are included...**
- timer.Pause()
- timer.Resume()
- timer.GetTimeRemaining()
- timer.GetRatioComplete()
- timer.isDone

### Motivation

Out of the box, there are two main ways of handling timers in Unity:
Expand All @@ -111,4 +118,4 @@ This library alleviates both of these concerns, making it easy to add an easy-to
### Usage Notes / Caveats

1. This library does not currently seem to work on the Hololens. We are looking into a solution for this.
2. Timers are destroyed when changing scenes.
2. All timers are destroyed when changing scenes. This behaviour is typically desired, and it happens because timers are updated by a TimerController that is also destroyed when the scene changes.

0 comments on commit 88567aa

Please sign in to comment.