유니티
로그라이크 - GameManager.cs
hololol
2019. 6. 24. 14:51
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
//점수를 저장해놨다가 씬이 끝날때 불러온다
public int playerFoodPoints = 100; //Player의 푸드점수
//public 인데 하이라키에 감추고 싶은것, 한번 움직이면 false가 됐다가 왔다갔다 변화값임
[HideInInspector] public bool playerTurn = true; //player가 턴을 했는가, 상태값 저장
BoardManager boardScript; //BoardManager를 담을 수 있는 변수
int level = 4;
private void Awake()
{
if(instance == null)
{
instance = this;
}
else if (instance!=null)
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
boardScript = GetComponent<BoardManager>();//boardManager를 getComponent로 가져와 boardScript에 담는다
InitGame();
}
private void InitGame()
{
//지금 레벨을 넣어서 SetupScene을 호출한다
boardScript.SetupScene(level);
}
void Restart()
{
/* 지금 활성중인 씬을 가져온다
* 인덱스, 네임 둘다 써도됨
* LoadSceneMode.Single - 열려져있는 모든씬을 닫고 새씬을 로드한다, 생략하면 나만 열림 */
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
}
public void GameOver()
{
//아무동작이 일어날 수 없도록 GameManager 스크립트를 꺼버린다.
enabled = false;
}
}