예제 #1
0
    private void Update()
    {
        TimeLeft -= Time.deltaTime;

        if (TimeLeft <= 0)
        {
            TimeLeft = 0;
            TimeIsUp?.Invoke();
            enabled = false;
        }
    }
예제 #2
0
        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();
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
 /// <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;
 }