private void Update() { TimeLeft -= Time.deltaTime; if (TimeLeft <= 0) { TimeLeft = 0; TimeIsUp?.Invoke(); enabled = false; } }
private void checkTimeLeft(object state) { if (paused) { return; } Pause(); if (TimeLeftPlayerBlack <= TimeSpan.Zero) { TimeIsUp?.Invoke(this, Color.Black); } else if (TimeLeftPlayerWhite <= TimeSpan.Zero) { TimeIsUp?.Invoke(this, Color.White); } Start(); }
private IEnumerator TimerCoroutine() { OutputTimerValue(_currentSecondsLeft); while (_currentSecondsLeft.HasValue && _currentSecondsLeft.Value > 0) { yield return(_waitOneSecond); if (_currentSecondsLeft.HasValue) { _currentSecondsLeft -= 1; } OutputTimerValue(_currentSecondsLeft); } if (_currentSecondsLeft.HasValue) { TimeIsUp?.Invoke(); } }
/// <summary> /// Set duration and callback of timer. /// </summary> /// <param name="duration">Duration of timer</param> /// <param name="timeIsUp">Callback function called when time is up</param> public void SetTimer(float duration, TimeIsUp timeIsUp) { this.duration = duration; timer = 0; this.timeIsUp = timeIsUp; }