6c84f865d8
1. 휴대폰에서 실시가능하도록 조이스틱 및 버튼 입력 2. 콜라이더 및 트리거 구조 변경 3. 로테이션 단계이상함 감지 - 수정 예정
77 lines
1.7 KiB
C#
77 lines
1.7 KiB
C#
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;
|
|
|
|
public GameObject restartButton;
|
|
|
|
public void EndGame()
|
|
{
|
|
isGameover = true;
|
|
gameoverText.SetActive(true);
|
|
restartButton.SetActive(true);
|
|
|
|
float bestTime = PlayerPrefs.GetFloat("BestTime");
|
|
if(surviveTime > bestTime)
|
|
{
|
|
bestTime = surviveTime;
|
|
PlayerPrefs.SetFloat("BestTime", bestTime);
|
|
}
|
|
|
|
recordText.text = "Best Time: " + (int)bestTime;
|
|
|
|
}
|
|
|
|
|
|
// 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
|
|
{
|
|
// 1. PC: R키
|
|
if (Input.GetKeyDown(KeyCode.R))
|
|
{
|
|
RestartGame();
|
|
}
|
|
// 2. 모바일/PC: 클릭 또는 터치 (화면 아무데나 눌러도 재시작)
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
RestartGame();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public float GetSurviveTime()
|
|
{
|
|
return surviveTime;
|
|
}
|
|
|
|
public void RestartGame()
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene(1);
|
|
}
|
|
}
|