void Update() { if (this.enabled) { timeText.enabled = true; } // Enable text object when the script is active if (currentTime <= 0f) // Disable component when countdown reaches 0 { OnCountdownFinished?.Invoke(this, new OnCountdownFinishedEventArgs { startSpawning = true }); // Send message to spawner to start spawning currentTime = startingTime; timeText.enabled = false; this.enabled = false; } else if (currentTime >= .5f) { DecreaseTime(); timeText.text = currentTime.ToString("0"); } else // When near 0 print GO { DecreaseTime(); timeText.text = "GO"; } }
/// <summary> /// Performs the countdown procedure before jumping. /// </summary> /// <returns>An awaitable task.</returns> private async Task LaunchCountdown() { CountdownPerSecond(); for (float t = 0; t < _warpCountdown; t += Time.deltaTime) { OnCountdownUpdate?.Invoke(this, new WarpCountdownArgs(_warpCountdown - t)); await Await.NextUpdate(); } OnCountdownFinished?.Invoke(this, EventArgs.Empty); }
public IEnumerator StartCountdownCoroutine(float countdownLength) { float myCounter = countdownLength; while (myCounter > 0) { myCounter = Mathf.Clamp(myCounter - Time.deltaTime, 0, countdownLength); myCountdownText.text = "" + Mathf.Ceil(myCounter); myBorder.fillAmount = myCounter % 1; yield return(null); } if (OnCountdownFinished != null) { OnCountdownFinished.Invoke(); } StartCoroutine(FadeUICoroutine()); }
/// <summary> /// Fires when countdown (3-1) finishes /// </summary> public void EventCountdownFinished() { OnCountdownFinished?.Invoke(); }