From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- TimeTrail.cs | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 TimeTrail.cs (limited to 'TimeTrail.cs') 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(); + if ((bool)populateArrayFromTransform) + { + targets = populateArrayFromTransform.GetComponentsInChildren(); + } + 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() + { + } +} -- cgit v1.1-26-g67d0