diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-18 00:08:07 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-18 00:08:07 +0200 |
commit | 18d6b012a6e9a74171e2ac484fc28d68c372a4bd (patch) | |
tree | b04b616115a7cb8c9d0498fb6e766556a8a39c23 /td/Assets/Scripts/FlashColor.cs | |
parent | 12b8646159169c082ae7197ed7af4bbcf1d9e2cb (diff) | |
download | TD-18d6b012a6e9a74171e2ac484fc28d68c372a4bd.tar.gz TD-18d6b012a6e9a74171e2ac484fc28d68c372a4bd.zip |
Added another tower, tweaked prices, by some reason waves are not always spawning...
Diffstat (limited to 'td/Assets/Scripts/FlashColor.cs')
-rw-r--r-- | td/Assets/Scripts/FlashColor.cs | 58 |
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; + } + } + + +} |