unirun1/Assets/Scripts/GameManager.cs

43 lines
955 B
C#
Raw Normal View History

2026-01-28 14:27:40 +00:00
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
public class GameManager : MonoBehaviour {
2026-01-29 02:32:06 +00:00
public static GameManager instance;
2026-01-28 14:27:40 +00:00
2026-01-29 02:32:06 +00:00
public bool isGameover = false;
public TextMeshProUGUI scoreText;
public GameObject gameoverUI;
2026-01-28 14:27:40 +00:00
2026-01-29 02:32:06 +00:00
private int score = 0;
2026-01-28 14:27:40 +00:00
void Awake() {
if (instance == null)
{
instance = this;
}
else
{
Debug.LogWarning("씬에 두개 이상의 게임 매니저가 존재합니다!");
Destroy(gameObject);
}
}
void Update() {
2026-01-29 02:32:06 +00:00
if (isGameover && Input.GetMouseButtonDown(0))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
2026-01-28 14:27:40 +00:00
}
public void AddScore(int newScore) {
2026-01-29 02:32:06 +00:00
score += newScore;
scoreText.text = "Score : " + score;
2026-01-28 14:27:40 +00:00
}
public void OnPlayerDead() {
2026-01-29 02:32:06 +00:00
isGameover = true;
gameoverUI.SetActive(true);
2026-01-28 14:27:40 +00:00
}
2026-01-29 02:32:06 +00:00
}