
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
주어진 스크립트를 다 넣었고 게임을 실행해서 level3까지 갔는데도 fatcat이 나타나지를 않아요.
gameManager에 fatCat prefab 스트립트도 들어가있는 상태입니다.
gameManager에서 makecat에서 normalCat 대신 fatCat이 시작부터 나오고 cat 스크립트 대로 실행되는 데 level3가 되어서는 나오지 않아요.
보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.

작성한 코드 및 에러 메세지
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cat : MonoBehaviour
{
float full = 5.0f;
float energy = 0.0f;
bool isFull = false;
public int type;
// Start is called before the first frame update
void Start()
{
float x = Random.Range(-8.5f, 8.5f);
float y = 30.0f;
if (type == 1)
{
full = 10.0f;
}
transform.position = new Vector3(x, y, 0);
}
// Update is called once per frame
void Update()
{
if (energy < full)
{
transform.position += new Vector3(0.0f, -0.05f, 0.0f);
if (transform.position.y < -16.0f)
{
gameManager.I.gameOver();
}
}
else
{
if (transform.position.x > 0)
{
transform.position += new Vector3(0.05f, 0.0f, 0.0f);
}
else
{
transform.position += new Vector3(-0.05f, 0.0f, 0.0f);
}
Destroy(gameObject, 3.0f);
}
}
void OnTriggerEnter2D(Collider2D coll)
{
if (coll.gameObject.tag == "food")
{
if (energy < full)
{
energy += 1.0f;
Destroy(coll.gameObject);
gameObject.transform.Find("hungry/Canvas/front").transform.localScale = new Vector3(energy / full, 1.0f, 1.0f);
}
else
{
if (isFull == false)
{
gameManager.I.addCat();
gameObject.transform.Find("hungry").gameObject.SetActive(false);
gameObject.transform.Find("full").gameObject.SetActive(true);
isFull = true;
}
}
}
}
}
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.
Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class gameManager : MonoBehaviour
{
public GameObject food;
public GameObject dog;
public GameObject normalCat;
public GameObject fatCat;
public GameObject retryBtn;
public Text levelText;
public GameObject levelFront;
public static gameManager I;
int level = 0;
int cat = 0;
void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
InvokeRepeating("makefood", 0.0f, 0.1f);
InvokeRepeating("makeCat", 0.0f, 1.0f);
}
// Update is called once per frame
void Update()
{
}
void makefood()
{
float x = dog.transform.position.x;
float y = dog.transform.position.y + 2.0f;
Instantiate(food, new Vector3(x, y, 0), Quaternion.identity);
}
void makeCat()
{
Instantiate(normalCat);
if (level == 1)
{
float p = Random.Range(0, 10);
if (p < 2) Instantiate(normalCat);
}
else if (level >= 2)
{
float p = Random.Range(0, 10);
if (p < 5) Instantiate(normalCat);
}
else if (level >= 3)
{
float p = Random.Range(0, 10);
if (p < 6) Instantiate(normalCat);
Instantiate(fatCat);
}
}
public void gameOver()
{
retryBtn.SetActive(true);
Time.timeScale = 0.0f;
}
public void addCat()
{
cat += 1;
level = cat / 5;
levelText.text = level.ToString();
levelFront.transform.localScale = new Vector3((cat - level * 5) / 5.0f, 1.0f, 1.0f);
}
}
