
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
과제 수행 중 스크립트 작성이 끝나고 실행을 하는데 레벨4가 되어도 해적고양이 생성이 안되고 아래와 같은 오류가 나옵니다.
작성한 코드 및 에러 메세지
에러 메시지
UnassignedReferenceException: The variable PirateCat of GameManager has not been assigned.
You probably need to assign the PirateCat variable of the GameManager script in the inspector. Parameter name: data
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.Bindings.ThrowHelper.ThrowArgumentNullException (System.Object obj, System.String parameterName) (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.Object.Internal_CloneSingle (UnityEngine.Object data) (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.Object.Instantiate[T] (T original) (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
GameManager.MakeCat () (at Assets/Scripts/GameManager.cs:68)
작성코드
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public GameObject normalCat;
public GameObject FatCat;
public GameObject PirateCat;
public GameObject retryBtn;
public RectTransform levelFront;
public Text levelTxt;
int level = 0;
int score = 0;
private void Awake()
{
if (instance == null)
{
instance = this;
}
Application.targetFrameRate = 60;
Time.timeScale = 1.0f;
}
void Start()
{
InvokeRepeating("MakeCat", 0f, 1f);
}
// Update is called once per frame
void MakeCat()
{
Instantiate(normalCat);
// lv.1 20% 확률로 고양이를 더 생성
if (level == 1)
{
int p = Random.Range(0, 10);
if (p < 2) Instantiate(normalCat);
}
else if (level == 2)
{
// lv.2 50% 확률로 고양이를 더 생성
int p = Random.Range(0, 10);
if (p < 5) Instantiate(normalCat);
}
else if (level == 3)
{
// lv.3 뚱냥이 생성
Instantiate(FatCat);
}
else if (level >= 4)
{
//해적고양이 생성
float p = Random.Range(0, 10);
if(p < 5) Instantiate(PirateCat);
Instantiate(FatCat);
Instantiate(PirateCat);
}
}
public void GameOver()
{
retryBtn.SetActive(true);
Time.timeScale = 0f;
}
public void AddScore()
{
score++;
level = score / 5;
levelTxt.text = level.ToString();
levelFront.localScale = new Vector3((score - level * 5) / 5.0f, 1f, 1f);
