diff options
Diffstat (limited to 'TimeTrail.cs')
-rw-r--r-- | TimeTrail.cs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/TimeTrail.cs b/TimeTrail.cs new file mode 100644 index 0000000..0f021a5 --- /dev/null +++ b/TimeTrail.cs @@ -0,0 +1,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() + { + } +} |