summaryrefslogtreecommitdiff
path: root/TimeTrail.cs
blob: 0f021a5000e0b630b01f3297c34c4cf2da8e81ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using TMPro;
using UnityEngine;

public class TimeTrail : MonoBehaviour
{
	public Transform populateArrayFromTransform;

	public Damagable[] targets;

	public TextMeshProUGUI text;

	public TextMeshProUGUI best;

	private int targetsKilled;

	private float counter;

	private bool done;

	private void Start()
	{
		text = GetComponentInChildren<TextMeshProUGUI>();
		if ((bool)populateArrayFromTransform)
		{
			targets = populateArrayFromTransform.GetComponentsInChildren<Damagable>();
		}
		Damagable[] array = targets;
		foreach (Damagable damagable in array)
		{
			damagable.outOfLiveEvent.AddListener(KillTarget);
		}
	}

	private void Update()
	{
		if (!done)
		{
			counter += Time.deltaTime;
		}
		if (Input.GetKey(KeyCode.P))
		{
			PlayerPrefs.SetFloat("Best", 999f);
		}
		best.text = "BEST: " + PlayerPrefs.GetFloat("Best");
		text.text = counter.ToString("f2");
	}

	public void KillTarget()
	{
		targetsKilled++;
		if (targetsKilled >= targets.Length)
		{
			Finish();
		}
	}

	private void Finish()
	{
		done = true;
		if (counter < PlayerPrefs.GetFloat("Best"))
		{
			PlayerPrefs.SetFloat("Best", counter);
		}
	}

	private void Restart()
	{
	}
}