2026-04-14 17:06:58 +09:00
|
|
|
using NUnit.Framework.Constraints;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class GameManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject gameoverText;
|
|
|
|
|
public Text timeText;
|
|
|
|
|
public Text recordText;
|
|
|
|
|
|
|
|
|
|
private float surviveTime;
|
|
|
|
|
private bool isGameover;
|
|
|
|
|
|
2026-04-21 17:45:51 +09:00
|
|
|
public GameObject restartButton;
|
|
|
|
|
|
2026-04-14 17:06:58 +09:00
|
|
|
public void EndGame()
|
|
|
|
|
{
|
|
|
|
|
isGameover = true;
|
|
|
|
|
gameoverText.SetActive(true);
|
2026-04-21 17:45:51 +09:00
|
|
|
restartButton.SetActive(true);
|
2026-04-14 17:06:58 +09:00
|
|
|
|
|
|
|
|
float bestTime = PlayerPrefs.GetFloat("BestTime");
|
|
|
|
|
if(surviveTime > bestTime)
|
|
|
|
|
{
|
|
|
|
|
bestTime = surviveTime;
|
|
|
|
|
PlayerPrefs.SetFloat("BestTime", bestTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recordText.text = "Best Time: " + (int)bestTime;
|
2026-04-21 17:45:51 +09:00
|
|
|
|
2026-04-14 17:06:58 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
surviveTime = 0;
|
|
|
|
|
isGameover = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if(!isGameover)
|
|
|
|
|
{
|
|
|
|
|
surviveTime += Time.deltaTime;
|
|
|
|
|
timeText.text = "Time: " + (int)surviveTime;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-04-21 17:45:51 +09:00
|
|
|
// 1. PC: R키
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.R))
|
|
|
|
|
{
|
|
|
|
|
RestartGame();
|
|
|
|
|
}
|
|
|
|
|
// 2. 모바일/PC: 클릭 또는 터치 (화면 아무데나 눌러도 재시작)
|
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
2026-04-14 17:06:58 +09:00
|
|
|
{
|
2026-04-21 17:45:51 +09:00
|
|
|
RestartGame();
|
2026-04-14 17:06:58 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetSurviveTime()
|
|
|
|
|
{
|
|
|
|
|
return surviveTime;
|
|
|
|
|
}
|
2026-04-21 17:45:51 +09:00
|
|
|
|
|
|
|
|
public void RestartGame()
|
|
|
|
|
{
|
|
|
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene(1);
|
|
|
|
|
}
|
2026-04-14 17:06:58 +09:00
|
|
|
}
|