| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | using UnityEngine.UI; |
| | | 5 | | using TMPro; |
| | | 6 | | |
| | | 7 | | public class Clock : MonoBehaviour |
| | | 8 | | { |
| | 6 | 9 | | public float time = 0; |
| | | 10 | | public TextMeshPro clockText; |
| | | 11 | | |
| | | 12 | | public BestTime BestTime; |
| | | 13 | | |
| | | 14 | | public GameObject test; |
| | | 15 | | |
| | | 16 | | public bool finished; |
| | | 17 | | |
| | | 18 | | private void Start() |
| | 2 | 19 | | { |
| | 2 | 20 | | finished = false; |
| | 2 | 21 | | } |
| | | 22 | | // Update is called once per frame |
| | | 23 | | void Update() |
| | 4910 | 24 | | { |
| | 4910 | 25 | | if (!finished) |
| | 140 | 26 | | { |
| | 140 | 27 | | time += Time.deltaTime; |
| | 140 | 28 | | TimeDisplay(time); |
| | 140 | 29 | | } |
| | 4910 | 30 | | } |
| | | 31 | | |
| | | 32 | | void TimeDisplay(float timeToDisplay) |
| | 140 | 33 | | { |
| | 140 | 34 | | if (timeToDisplay < 0) |
| | 0 | 35 | | { |
| | 0 | 36 | | timeToDisplay = 0; |
| | 0 | 37 | | } |
| | | 38 | | |
| | 140 | 39 | | float minutes = Mathf.FloorToInt(timeToDisplay / 60); |
| | 140 | 40 | | float seconds = Mathf.FloorToInt(timeToDisplay % 60); |
| | 140 | 41 | | clockText.text = string.Format("{0:00}:{1:00}", minutes, seconds); |
| | 140 | 42 | | } |
| | | 43 | | |
| | | 44 | | public void onFinish() |
| | 10 | 45 | | { |
| | 10 | 46 | | BestTime.checkTime(time); |
| | 10 | 47 | | finished = true; |
| | 10 | 48 | | } |
| | | 49 | | |
| | | 50 | | public void onTimeOut() |
| | 2 | 51 | | { |
| | 2 | 52 | | finished = true; |
| | 2 | 53 | | } |
| | | 54 | | } |