
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
끝나면 고양이가 사라져야하는데 사라지지 않습니다.

작성한 코드 및 에러 메세지
[GameManager.cs]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public GameObject normalCat;
public GameObject retryBtn;
private void Awake()
{
if (Instance == null)
{
Instance = this; //싱클톤
}
Application.targetFrameRate = 60; // Cat.cs에서 옮
Time.timeScale = 1.0f; // 리트라이 버튼이 나오면 더이상 고양이가 나오지 않게됨?
}
void Start()
{
InvokeRepeating("MakeCat", 0f, 1f);
}
void Update()
{
}
void MakeCat()
{
Instantiate(normalCat);
}
public void GameOver()
{
retryBtn.SetActive(true);
}
}
------------------
[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;
void Start()
{
float x = Random.Range(-9.0f, 9.0f);
float y = 30.0f;
transform.position = new Vector2(x, y);
}
void Update()
{
if(energy < full)
{
transform.position += Vector3.down * 0.05f;
if (transform.position.y < -16.0f)// 고양이가 닿았을 때
{
GameManager.Instance.GameOver(); //Application.targetFrameRate = 60;은 GameManager.cs로 옮김
}
}
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)
{
hungryCat.SetActive(false);
fullCat.SetActive(true);
Destroy(gameObject, 3.0f);
}
}
}
}
}
