Files
unity-application/Assets/Scripts/Timer.cs
2023-03-02 17:11:57 +01:00

35 lines
740 B
C#

using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
private float timerValue;
public Text timerText;
void Start()
{
timerValue = 0.0f;
timerText = GetComponent<Text>();
}
void Update()
{
timerValue -= Time.deltaTime;
if (timerValue <= 0.0f)
{
timerValue = 0.0f;
// Handle end of timer
}
int minutes = Mathf.FloorToInt(timerValue / 60.0f);
int seconds = Mathf.FloorToInt(timerValue % 60.0f);
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
void addSeconds(int seconds) {
timerValue += (float) seconds;
}
}