노마드코더 채널에 있는 유니티6강의 영상 보고 따라하는데 에러났거든?
찾아보니까 에러나도 실행은 정상적으로 된다던데 나는 에러를 해결해야만 실행된다고 떠서 질문함
문제의 코드
using UnityEngine;
using UnityEngine.SceneManagement;
public enum GameState{
Intro ,
Playing,
Dead
}
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public GameState state = GameState.Intro;
public float PlayStartTime;
public int lives = 3;
[Header("References")]
public GameObject IntroUI;
public GameObject DeadUI;
public GameObject EnemySpawner;
public GameObject FoodSpawner;
public GameObject GoldenSpawner;
public Player PlayerScript;
public TMP_Text ScoreText;
void Awake(){
if(Instance == null){
Instance = this;
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
IntroUI.SetActive(true);
}
float calculateScore(){
return Time.time-PlayStartTime;
}
void SaveHighScore(){
int score = Mathf.FloorToInt(calculateScore());
int CurrentHighScore=PlayerPrefs.GetInt("highScore");
if(score > CurrentHighScore){
PlayerPrefs.SetInt("highScore",score);
PlayerPrefs.Save();
}
}
// Update is called once per frame
void Update()
{
if(state == GameState.Playing){
ScoreText.text="Score: "+Mathf.FloorToInt(calculateScore());
}
if(state == GameState.Intro && Input.GetKeyDown(KeyCode.Space)){
state= GameState.Playing;
IntroUI.SetActive(false);
EnemySpawner.SetActive(true);
FoodSpawner.SetActive(true);
GoldenSpawner.SetActive(true);
PlayStartTime = Time.time;
}
if(state == GameState.Playing && lives<=0){
PlayerScript.KillPlayer();
EnemySpawner.SetActive(false);
FoodSpawner.SetActive(false);
GoldenSpawner.SetActive(false);
DeadUI.SetActive(true);
state=GameState.Dead;
}
if(state == GameState.Dead && Input.GetKeyDown(KeyCode.Space)){
SceneManager.LoadScene("Main");
}
}
}
맨 위에 using TMPro; 넣으셈
ㄳㄳ
tmp_text 타입은 네임스페이스가 따로 있음. 뭐였는진 기억 안 나는데 대충 ctrl + . 하면 네임스페이스 알아서 using 시켜줄걸 - dc App
와이걸 뱌워야하네 ㄷㄷ