
안녕하세요
levelText와 levelFront를 모두 변경해주었는데도 level의 상태바와 숫자가 변하지 않아 문의드립니다
scale와 position을 모두 맞춰주었고 cat.cs 에도 동일하게 addCat를 적용하였으며 5마리 이상이 food와 충돌하였는데도 값이 변하지 않습니다.

.
작성한 코드 및 에러 메세지
gameManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class gameManager : MonoBehaviour
{
public GameObject dog;
public GameObject food;
public GameObject normalCat;
public static gameManager I;
public GameObject retryBtn;
int level = 0;
int cat = 0;
public Text levelText;
public GameObject levelFront;
void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
InvokeRepeating("makeFood", 0, 0.2f);
InvokeRepeating("makeCat", 0, 1f);
}
// 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);
}
public void gameOver()
{
retryBtn.SetActive(true);
Time.timeScale = 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);
}
}
cat.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cat : MonoBehaviour
{
float full = 5f;
float energy = 0f;
bool isFull = false;
// Start is called before the first frame update
void Start()
{
float x = Random.Range(-8.5f,8.5f);
float y = 30f;
transform.position = new Vector3(x,y,0);
}
// Update is called once per frame
void Update()
{
if(energy < full)
{
transform.position += new Vector3(0,-0.05f,0);
if(transform.position.y < -16f)
{
gameManager.I.gameOver();
}
}
else
{
if(transform.position.x>0)
{
transform.position += new Vector3(0.5f,0,0);
}
else
{
transform.position += new Vector3(-0.5f,0,0);
}
Destroy(gameObject, 3.0f);
}
}
void OnTriggerEnter2D(Collider2D coll)
{
if (coll.gameObject.tag == "food")
{
if(energy < full)
{
energy += 1f;
Destroy(coll.gameObject);
gameObject.transform.Find("hungry/Canvas/front").transform.localScale = new Vector3(energy / full, 1, 1);
}
else
{
if (isFull == false)
{
gameManager.I.addCat();
gameObject.transform.Find("hungry").gameObject.SetActive(false);
gameObject.transform.Find("full").gameObject.SetActive(true);
isFull = true;
}
}
}
}
}
