Skip to content
Snippets Groups Projects

electricity: make electricity blink when out of energy

Merged Verin Antoine requested to merge 66-electricity into main
Compare and
1 file
+ 25
0
Preferences
Compare changes
using System.Collections;
using Src;
using UnityEngine;
using UnityEngine.UI;
@@ -12,6 +13,7 @@ namespace UI
public class Scoreboard : MonoBehaviour
{
private bool _blinking;
private Text _text;
private void Start()
@@ -22,6 +24,29 @@ namespace UI
private void Update()
{
_text.text = "Electricit: " + GameManager.Instance.GetModifier(ModifierType.Electricity);
if (GameManager.Instance.GetModifier(ModifierType.Electricity) < 0 && !_blinking)
{
StartCoroutine(nameof(Blinking));
_blinking = true;
}
if (GameManager.Instance.GetModifier(ModifierType.Electricity) > 0 && _blinking)
{
StopCoroutine(nameof(Blinking));
_blinking = false;
}
}
private IEnumerator Blinking()
{
while (true)
{
_text.color = Color.red;
yield return new WaitForSeconds(.5f);
_text.color = Color.white;
yield return new WaitForSeconds(.5f);
}
}
}
}