BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / TimerTextController.cs

TimerTextController.cs

f93b9f9e History
TimerTextController.cs 976 B Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public 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}