2e4370481b
1. 총알피하기 게임 제작 2. 시간별로 단계 설정 3. 시작화면 및 이펙트, 사운드 삽입
62 lines
1.3 KiB
C#
62 lines
1.3 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 void EndGame()
|
|
{
|
|
isGameover = true;
|
|
gameoverText.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
|
|
{
|
|
if(Input.GetKeyDown(KeyCode.R))
|
|
{
|
|
SceneManager.LoadScene("Game");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public float GetSurviveTime()
|
|
{
|
|
return surviveTime;
|
|
}
|
|
}
|