
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
계속 늘어납니다. 그리고 한마리를 잡은 시점부터 이미 바를 넘어갑니다.

작성한 코드 및 에러 메세지
GameManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public GameObject normalCat;
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;
}
// Start is called before the first frame update
void Start()
{
InvokeRepeating("MakeCat", 0f, 1f);
}
// Update is called once per frame
void Update()
{
}
void MakeCat()
{
Instantiate(normalCat);
}
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 / 3.0f, 1f, 1f);
}
}
cat.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cat : MonoBehaviour
{
public GameObject hungrycat;
public GameObject Fullcat;
public RectTransform front;
float Full = 5.0f;
float energy = 0.0f;
bool isFull = false;
// Start is called before the first frame update
void Start()
{
float x = Random.Range(-9.0f, 9.0f);
float y = 30.0f;
transform.position = new Vector2(x, y);
}
// Update is called once per frame
void Update()
{
if (energy < Full)
{
transform.position += Vector3.down * 0.05f;
if(transform.position.y < -16.0f)
{
GameManager.Instance.GameOver();
}
}
else
{
if(transform.position.x > 0)
{
transform.position += Vector3.right * 0.05f;
}
else
{
transform.position += Vector3.left * 0.05f;
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Food"))
{
if(energy < Full)
{
energy += 1.0f;
front.localScale = new Vector3(energy / Full, 1.0f, 1.0f);
Destroy(collision.gameObject);
if(energy == 5.0f)
{
if(!isFull)
{
isFull = true;
hungrycat.SetActive(false);
Fullcat.SetActive(true);
Destroy(gameObject, 3.0f);
GameManager.Instance.AddScore();
}
}
}
}
}
}
