
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
뚱뚱한 고양이가 생성은 되는데 밥을 일반 고양이랑 동일하게 5번을 먹고 배부른 상태로 됩니다. 스크립트 수정해서 타입도 변경을 해봤는데 해결이 안돼서 질문 남깁니다.
작성한 코드 및 에러 메세지
public class Cat : MonoBehaviour
{
public GameObject hungryCat;
public GameObject fullCat;
public RectTransform front;
public int type;
float full = 5.0f;
float energy = 0.0f;
float speed = 0.5f;
bool isFull = false;
void Start()
{
float x = Random.Range(-9.0f, 9.0f);
float y = 30.0f;
transform.position = new Vector2(x, y);
if(type == 1)
{
speed = 0.02f;
full = 10.0f;
}
else if(type == 2)
{
speed = 0.05f;
full = 5.0f;
}
}
// Update is called once per frame
void Update()
{
if (energy < full)
{
transform.position += Vector3.down * speed;
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();
}
}
}
}
}
}
