added comments and organized project files

This commit is contained in:
djkellerman
2025-03-28 17:39:07 -04:00
parent 22f44a3f20
commit a098e8c053
84 changed files with 183 additions and 214 deletions

View File

@@ -0,0 +1,58 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class GameTimer : MonoBehaviour
{
public float startTime = 180f;
private float timeRemaining;
private bool timerRunning = false;
public Text timerText;
[SerializeField] private TextMeshProUGUI timer;
private void Start()
{
timeRemaining = startTime;
timer.text = "3:00.00";
UpdateTimerDisplay();
}
private void Update() // Updates the timer to show the time remaining
{
if (timerRunning)
{
timeRemaining -= Time.deltaTime;
if (timeRemaining <= 0)
{
timeRemaining = 0;
timerRunning = false;
OnTimerEnd();
}
UpdateTimerDisplay();
}
}
public void StartTimer() // Starts the timer
{
if (!timerRunning)
{
timeRemaining = startTime;
timerRunning = true;
}
}
private void UpdateTimerDisplay() // Formats and sets the time remaining
{
int minutes = Mathf.FloorToInt(timeRemaining / 60);
int seconds = Mathf.FloorToInt(timeRemaining % 60);
timer.text = string.Format("{0}:{1:D2}", minutes, seconds);
}
private void OnTimerEnd() // Ends the game when the time runs out
{
GameManager.Instance.GameOver();
}
}