public void ShowOutOfAmmo() { if (_canFlashAmmoText) { CanFlash handler = CanFlashAmmo; StartCoroutine(FlashText(_ammoText, handler, RedText, 3)); } }
public void UpdateAmmo(int newAmmo) { if (_canFlashAmmoText && newAmmo > _currentAmmo) { CanFlash handler = CanFlashAmmo; StartCoroutine(FlashText(_ammoText, handler, GreenText)); } _currentAmmo = newAmmo; _ammoText.text = "Ammo: " + _currentAmmo; }
IEnumerator OverHeatRoutine() { while (_overHeat) { if (_canFlashEngineOverHeatText) { CanFlash handler = CanFlashOverHeat; StartCoroutine(FlashText(_engineOverHeatText, handler, RedText)); } yield return(new WaitForSeconds(_textFlashOnDelay + _textFlashBetweenDelay + 0.01f)); // total runtime of FlashText plus a small buffer } }
public void UpdateScore(int newScore) { if (_canFlashScoreText && newScore != _currentScore) { Color color; if (newScore > _currentScore) { color = GreenText; } else { color = RedText; } CanFlash handler = CanFlashScore; StartCoroutine(FlashText(_scoreText, handler, color)); } _currentScore = newScore; _scoreText.text = "Score: " + _currentScore; }
IEnumerator FlashText(Text text, CanFlash canFlash, Color flashColor, int count = 1) { canFlash(false); Color originalColor = text.color; while (count > 0) { count--; text.color = flashColor; yield return(new WaitForSeconds(_textFlashOnDelay)); text.color = originalColor; yield return(new WaitForSeconds(_textFlashBetweenDelay)); } canFlash(true); }