MiniGames/Assets/Scripts/ChaseOn/ChaseScoreManager.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2025-07-30 01:38:12 +05:00
using UnityEngine;
using UnityEngine.UI;
using TMPro;
2025-08-06 19:14:48 +05:00
using UnityEngine.SceneManagement;
2025-07-30 01:38:12 +05:00
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<ChasePlayerController>().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;
}
2025-08-06 19:14:48 +05:00
public void Restart()
{
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
2025-07-30 01:38:12 +05:00
}