30 lines
470 B
C#
30 lines
470 B
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class GameTimer : MonoBehaviour {
|
|
TMP_Text label;
|
|
float timer;
|
|
bool stopped;
|
|
|
|
void Awake() {
|
|
label = GetComponent<TMP_Text>();
|
|
stopped = true;
|
|
}
|
|
|
|
public void StartTimer() {
|
|
timer = Time.time;
|
|
stopped = false;
|
|
}
|
|
|
|
public void PauseTimer() => stopped = true;
|
|
|
|
void Update() {
|
|
if (stopped)
|
|
return;
|
|
|
|
timer += Time.deltaTime;
|
|
label.text = TimeSpan.FromSeconds(timer)
|
|
.ToString(@"mm\:ss");
|
|
}
|
|
} |