
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
밥이 무한생성이 되지 않고 하나밖에 안나와요
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()
{
Time.timeScale = 1f;
InvokeRepeating("makeFood", 0.0f, 0.05f);
InvokeRepeating("makeCat", 0.0f, 1f);
}
// Update is called once per frame
void Update()
{
transform.position += new Vector3(0.0f, 0.5f, 0.0f);
if (transform.position.y > 26.0f)
{
Destroy(gameObject);
}
}
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.5) Instantiate(normalCat);
Instantiate(fatCat);
}
}
public void gameOver()
{
Time.timeScale = 0f;
retryBtn.SetActive(true);
}
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);
}
}
일단 보류해두고 진도를 끝까지 나갔는데
마찬가지로 고양이도 무한생성이 안되네요
콘솔에 오류가 엄청 많이 뜨는데
UnassignedReferenceException: The variable dog of gameManager has not been assigned.
You probably need to assign the dog variable of the gameManager script in the inspector.
gameManager.makeFood () (at Assets/Scripts/gameManager.cs:44)
UnassignedReferenceException: The variable normalCat of gameManager has not been assigned.
You probably need to assign the normalCat variable of the gameManager script in the inspector.
UnityEngine.Object.Instantiate[T] (T original) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
gameManager.makeCat () (at Assets/Scripts/gameManager.cs:51)
UnassignedReferenceException: The variable retryBtn of gameManager has not been assigned.
You probably need to assign the retryBtn variable of the gameManager script in the inspector.
gameManager.gameOver () (at Assets/Scripts/gameManager.cs:73)
cat.Update () (at Assets/Scripts/cat.cs:40)
이렇게 세가지가 계속 떠요
