using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.SceneManagement; public class ChaseScoreManager : MonoBehaviour { public TextMeshProUGUI scoreText; public float timeScoreRate = 1f; // Score units per second private int score = 0; private float timeAccumulator = 0f; public GameObject GameOverPanel; public void GameOver() { if (GameOverPanel != null) GameOverPanel.SetActive(true); Time.timeScale = 0; // Optional: prevent further score updates or player control GameObject player = GameObject.FindGameObjectWithTag("Player"); if (player != null) player.GetComponent().enabled = false; } void Update() { // Add score based on time timeAccumulator += Time.deltaTime * timeScoreRate; if (timeAccumulator >= 1f) { int intPoints = Mathf.FloorToInt(timeAccumulator); AddScore(intPoints); timeAccumulator -= intPoints; } } public void AddScore(int value) { score += value; scoreText.text = "Score: " + score; } public void Restart() { Time.timeScale = 1; SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } }