aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/FlashColor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'td/Assets/Scripts/FlashColor.cs')
-rw-r--r--td/Assets/Scripts/FlashColor.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/td/Assets/Scripts/FlashColor.cs b/td/Assets/Scripts/FlashColor.cs
new file mode 100644
index 0000000..b5da678
--- /dev/null
+++ b/td/Assets/Scripts/FlashColor.cs
@@ -0,0 +1,58 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class FlashColor : MonoBehaviour {
+
+ public Color Color1;
+ public Color Color2;
+ public float TransitionTime;
+ public bool HideAfterCountdown;
+ public float DisplayTime;
+
+ private Text _text;
+ public float TimeSinceBorn;
+
+ void Start() {
+ TimeSinceBorn = 0;
+ _text = gameObject.GetComponent<Text>();
+ StartCoroutine("Flash");
+ }
+
+ void OnEnable() {
+ TimeSinceBorn = 0;
+ _text = gameObject.GetComponent<Text>();
+ StartCoroutine("Flash");
+ }
+
+ void Update () {
+ if (HideAfterCountdown) {
+ TimeSinceBorn += Time.deltaTime;
+ if (TimeSinceBorn >= DisplayTime) {
+ gameObject.SetActive(false);
+ }
+ }
+ }
+
+ IEnumerator Flash() {
+ while (true) {
+ float elapsedTime = 0.0f;
+ while (elapsedTime < TransitionTime) {
+ elapsedTime += Time.deltaTime;
+ _text.color = Color.Lerp(Color1, Color2, (elapsedTime / TransitionTime));
+ yield return null;
+ }
+
+ elapsedTime = 0.0f;
+ while (elapsedTime < TransitionTime) {
+ elapsedTime += Time.deltaTime;
+ _text.color = Color.Lerp(Color2, Color1, (elapsedTime / TransitionTime));
+ yield return null;
+ }
+ yield return null;
+ }
+ }
+
+
+}