정상작동 - 고양이의 hp바가 다 차면 새로운 이미지로 교체
하지만 setActive가 제대로 작동 안되는 문제 확인
(full 이미지의 고양이가 나오지 않음)
고양이의 hp바가 모두 찼는데도 full은 여전히 active = false 상태
코드 진행을 알기 위해 로그로 찍어보았다
if (coll.gameObject.tag == "food"){
if (energy < full){
Debug.Log(energy);
energy += 1.0f;
Destroy(coll.gameObject);
gameObject.transform.Find("hungry/Canvas/front").transform.localScale = new Vector3(energy / full, 1.0f, 1.0f);
}else{
Debug.Log("full"); //출력 x
gameObject.transform.Find("full").gameObject.SetActive(true);
gameObject.transform.Find("hungry").gameObject.SetActive(false);
}
}

원인이 if 조건문에 있을 것 같다는 생각.
만약 고양이의 피가 4가 차있을때 먹이를 먹고 5가 되는 순간 full로 간주해야함.
하지만 지금 코드로 4에서 5가 되고 나서도 먹이를 한번 더 먹어야 if조건문에 진입을 하기 때문에 if문에 새로운 if문을 넣어주기로 했다.
수정한 코드
if (coll.gameObject.tag == "food"){
if (energy < full){
energy += 1.0f;
Debug.Log(energy);
Destroy(coll.gameObject);
gameObject.transform.Find("hungry/Canvas/front").transform.localScale = new Vector3(energy / full, 1.0f, 1.0f);
if (energy == full){
Debug.Log("full");
gameObject.transform.Find("full").gameObject.SetActive(true);
gameObject.transform.Find("hungry").gameObject.SetActive(false);
}
}
}
5가 되는 순간 full 출력. else문에 정상적으로 들어가는 것을 확인.