Created
August 2, 2015 11:01
-
-
Save TheLouisHong/39323b4a4cd27b498165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class PausableTimer { | |
private float _timerStart = -1; | |
private float _timerTime; | |
public PausableTimer(float initialTimerTime = 0) { | |
_timerTime = initialTimerTime; | |
} | |
public float TimerTime { | |
get { | |
if (_timerStart != -1) { | |
return _timerTime + Time.time - _timerStart; | |
} | |
return _timerTime; | |
} | |
set { _timerTime = value; } | |
} | |
public void StartTimer() { | |
if (_timerStart == -1) { | |
_timerStart = Time.time; | |
} | |
} | |
public void PauseTimer() { | |
if (_timerStart != -1) { | |
_timerTime += Time.time - _timerStart; | |
_timerStart = -1; | |
} | |
} | |
public void ResetTimer() { | |
PauseTimer(); | |
_timerTime = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment