From 95ba54b66b2f6de91bd99ab6f8fcbb9f69631238 Mon Sep 17 00:00:00 2001 From: hani-sayegh Date: Fri, 10 Mar 2017 18:09:02 -0600 Subject: [PATCH] count down timer --- Assets/hanisstuff/scripts/TimeLineUI.cs | 39 +++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Assets/hanisstuff/scripts/TimeLineUI.cs b/Assets/hanisstuff/scripts/TimeLineUI.cs index 4f4f261..442b5ba 100644 --- a/Assets/hanisstuff/scripts/TimeLineUI.cs +++ b/Assets/hanisstuff/scripts/TimeLineUI.cs @@ -17,7 +17,7 @@ public class TimeLineUI : MonoBehaviour private float startTime; private int yOffset = -5; private Image playerTimeLine; - //public LineRenderer thisTimeLine; + private GameObject timeLine; void Start() { @@ -31,13 +31,13 @@ void Start() //thisTimeLine.SetPosition(0, new Vector2(0, -10)); //thisTimeLine.SetPosition(1, new Vector2(midpoint, -10)); secondsOnScreen = new List(); - var timeLine = GameObject.FindGameObjectWithTag("TimeLine"); + timeLine = GameObject.FindGameObjectWithTag("TimeLine"); transform = GetComponent(); widthBetweenSeconds = Screen.width / (float)10; for (int i = 0; i < intervalCount + 1; ++i) { var temp = Instantiate(second); - temp.transform.parent = timeLine.transform; + temp.transform.SetParent(timeLine.transform); temp.text = i.ToString(); temp.rectTransform.anchoredPosition = new Vector2(i * widthBetweenSeconds, yOffset); secondsOnScreen.Add(temp); @@ -46,15 +46,42 @@ void Start() private int direction = 1; private int earliestSecond; - private float playerTimeLineScale; + private List cloneWarpoutTimes = new List(); + + public class CloneUI + { + public Text timeS; + public float timeF; + public CloneUI(Text t, float f) + { + timeS = t; + timeF = f; + } + } + void Update() { if (Input.GetKeyDown(KeyCode.L)) { direction = -direction; - //only if going back in time - playerTimeLineScale = widthBetweenSeconds * Time.time; + var cloneWarpoutTime = Time.time - startTime; + startTime = Time.time; + + var temp = Instantiate(second); + temp.transform.SetParent(timeLine.transform); + temp.text = cloneWarpoutTime.ToString(); + temp.rectTransform.anchoredPosition = new Vector2(0, -100); + cloneWarpoutTimes.Add(new CloneUI(temp, cloneWarpoutTime)); } + for (int i = 0; i < cloneWarpoutTimes.Count; ++i) + { + cloneWarpoutTimes[i].timeS.text = (cloneWarpoutTimes[i].timeF -= Time.deltaTime).ToString(); + //if (cloneWarpoutTimes[i].timeF < 0) + + + } + + foreach (var second in secondsOnScreen) {