ReplayPuzzleGame/Assets/Scripts/GameTimer.cs

24 lines
636 B
C#
Raw Normal View History

2026-01-31 15:55:27 +00:00
using UnityEngine;
using TMPro;
public class GameTimer : MonoBehaviour
{
[SerializeField] TextMeshProUGUI timerText;
[SerializeField] private float currentTime;
void Update()
{
if (currentTime > 0)
{
currentTime -= Time.deltaTime;
}
else if (currentTime < 0)
{
currentTime = 0;
timerText.color = Color.blue;
//GameOver();
}
int minutes = Mathf.FloorToInt(currentTime / 60);
int second = Mathf.FloorToInt(currentTime % 60);
timerText.text = string.Format("{0:00} : {1:00}", minutes, second);
}
}