| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class TimerTextController : MonoBehaviour |
| 6 | { |
| 7 | private TextMesh textMesh; |
| 8 | [SerializeField] private ModuleSpawnerController timecontroller; |
| 9 | |
| 10 | // Start is called before the first frame update |
| 11 | void Start() |
| 12 | { |
| 13 | textMesh = GetComponent<TextMesh>(); |
| 14 | } |
| 15 | |
| 16 | // Update is called once per frame |
| 17 | void Update() |
| 18 | { |
| 19 | int seconds = Mathf.RoundToInt(timecontroller.SecondsRemainingUntilLoss); |
| 20 | |
| 21 | int minutes = 0; |
| 22 | |
| 23 | while(seconds >= 60) |
| 24 | { |
| 25 | seconds -= 60; |
| 26 | minutes++; |
| 27 | } |
| 28 | |
| 29 | string secondString = seconds.ToString(); |
| 30 | |
| 31 | if (secondString.Length == 1) |
| 32 | secondString = "0" + secondString; |
| 33 | |
| 34 | string minuteString = minutes.ToString(); |
| 35 | |
| 36 | if (minuteString.Length == 1) |
| 37 | minuteString = "0" + minuteString; |
| 38 | |
| 39 | textMesh.text = minuteString + ":" + secondString; |
| 40 | } |
| 41 | } |