From 18d6b012a6e9a74171e2ac484fc28d68c372a4bd Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Wed, 18 Oct 2017 00:08:07 +0200 Subject: Added another tower, tweaked prices, by some reason waves are not always spawning... --- td/Assets/Scripts/FlashColor.cs | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 td/Assets/Scripts/FlashColor.cs (limited to 'td/Assets/Scripts/FlashColor.cs') 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(); + StartCoroutine("Flash"); + } + + void OnEnable() { + TimeSinceBorn = 0; + _text = gameObject.GetComponent(); + 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; + } + } + + +} -- cgit v1.2.3