Skip to content

Commit

Permalink
count down timer
Browse files Browse the repository at this point in the history
  • Loading branch information
hani-sayegh committed Mar 11, 2017
1 parent e3abf8e commit 95ba54b
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions Assets/hanisstuff/scripts/TimeLineUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -31,13 +31,13 @@ void Start()
//thisTimeLine.SetPosition(0, new Vector2(0, -10));
//thisTimeLine.SetPosition(1, new Vector2(midpoint, -10));
secondsOnScreen = new List<Text>();
var timeLine = GameObject.FindGameObjectWithTag("TimeLine");
timeLine = GameObject.FindGameObjectWithTag("TimeLine");
transform = GetComponent<RectTransform>();
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);
Expand All @@ -46,15 +46,42 @@ void Start()

private int direction = 1;
private int earliestSecond;
private float playerTimeLineScale;
private List<CloneUI> cloneWarpoutTimes = new List<CloneUI>();

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)
{
Expand Down

0 comments on commit 95ba54b

Please sign in to comment.