44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
![]() |
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using TMPro;
|
||
|
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;
|
||
|
}
|
||
|
}
|