// Update is called once per frame void Update() { if (gameStarted && TimeRemaining.TotalSeconds > 0) { TimeRemaining = TimeRemaining.Subtract(TimeSpan.FromSeconds(Time.deltaTime)); var timer = GameObject.Find("Timer").GetComponent <Text>(); timer.text = $"{TimeRemaining.Minutes.ToString("00")}:{TimeRemaining.Seconds.ToString("00")}"; if (TimeRemaining <= TimeSpan.FromSeconds(0.17 * TimeInSeconds)) { timer.color = Color.red; } else if (TimeRemaining <= TimeSpan.FromSeconds(0.5 * TimeInSeconds)) { timer.color = Color.yellow; } else { timer.color = Color.white; } } else if (TimeRemaining.TotalSeconds < 1) { gameOver(); } }
/// <summary> /// Executes the cooking processes. /// </summary> private void Cook() { TimeRemaining = TimeRemaining.Subtract(new TimeSpan(0, 0, 1)); //if (TimeRemaining == new TimeSpan()) //{ // Stop(); //} }
private void Tick(object sender, ElapsedEventArgs e) { if (TimeRemaining == null || TimeRemaining.TotalMilliseconds <= timer.Interval) { TimeRemaining = new TimeSpan(); } else { TimeRemaining.Subtract(TimeSpan.FromMilliseconds(timer.Interval)); } }
public void Decrement() { TimeRemaining = TimeRemaining.Subtract(TimeSpan.FromSeconds(1)); }