
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
if(transform.position.x > 0)
{
transform.position += Vector3.right * 0.05f;
}
else
{
transform.position += Vector3.left * 0.05f;
해당 부분의 Vector3.left * 0.05f; 에서 0.09f 이상의 값이 들어가면 고양이의 배고픔이 full 이 되었을 때 full 이미지로 바뀌지 않고 그냥 이동합니다.
추가로 고양이의 게이지가 full이 되었을 때 Hungry이미지 에서 Full이미지로 바뀌는 시간이 조금 걸리는데 그 딜레이를 줄일 수 있는 방법이 있을까요?


화면밖으로 나갈때까지도 계속 Full 이미지로 바뀌지 않는 모습
작성한 코드 및 에러 메세지
public class Cat : MonoBehaviour
{
public GameObject hungryCat;
public GameObject fullCat;
public RectTransform front;
float full = 5.0f;
float energy = 0.0f;
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = 60; // 모든 컴퓨터의 프레임값 기준으로 속도 설정
}
// Update is called once per frame
void Update()
{
if(energy < full)
{
transform.position += Vector3.down * 0.05f;
}
else
{
if(transform.position.x > 0)
{
transform.position += Vector3.right * 0.09f;
}
else
{
transform.position += Vector3.left * 0.09f;
}
}
}
// Rigidbody 속성을 kinematic으로 바꾸면서 concollision2D를 못쓰게되었음
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);
}
else
{
hungryCat.SetActive(false);
fullCat.SetActive(true);
}
}
}
}
