커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
해적고양이 생성이 안 됩니다.
게임 개발이 처음이어도 쉽게 배우는 모바일 게임 개발
3주차
북마크
성*창
댓글
3
추천
0
조회수
9
조회수
9
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


과제 수행 중 스크립트 작성이 끝나고 실행을 하는데 레벨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);








취소
 공유
취소
댓글 0
댓글 알림
나의얼굴