KeepAway updates + GameTimer

This commit is contained in:
djkellerman
2025-03-20 14:45:29 -04:00
parent a3e2c9c6e2
commit 0a13e9ccd3
23 changed files with 462 additions and 77 deletions

View File

@@ -0,0 +1,56 @@
using UnityEngine;
using UnityEngine.UI;
public class GameTimer : MonoBehaviour
{
public float startTime = 180f;
private float timeRemaining;
private bool timerRunning = false;
public Text timerText;
private void Start()
{
timeRemaining = startTime;
UpdateTimerDisplay();
}
private void Update()
{
if (timerRunning)
{
timeRemaining -= Time.deltaTime;
if (timeRemaining <= 0)
{
timeRemaining = 0;
timerRunning = false;
OnTimerEnd();
}
UpdateTimerDisplay();
}
}
public void StartTimer()
{
if (!timerRunning)
{
timeRemaining = startTime;
timerRunning = true;
}
}
private void UpdateTimerDisplay()
{
int minutes = Mathf.FloorToInt(timeRemaining / 60);
int seconds = Mathf.FloorToInt(timeRemaining % 60);
timerText.text = string.Format("{0:D2}:{1:D2}", minutes, seconds);
}
private void OnTimerEnd()
{
Debug.Log("Timer ended! KeepAway mode has finished.");
GameManager.Instance.GameOver();
}
}