OnEat이라는 이벤트를 실행하면 IsEat bool값을 true로 반환해준다.
public void OnEat(InputAction.CallbackContext context)
{
if(context.phase == InputActionPhase.Started && interactable != null)
{
if(InteractGameObject.gameObject.tag == "Food")
{
IsEat = true;
condition.Eat();
Destroy(InteractGameObject.gameObject);
InteractGameObject = null;
interactable = null;
prompText.gameObject.SetActive(false);
}
else
{
Debug.Log("음식이 아닙니다.");
}
}
}
IsEat이 true라면 코루틴을 이용해 아이템을 효과를 적용시켰습니다.
public void Eat()
{
if (interaction.IsEat == true)
{
StartCoroutine(EatFood());
}
}
IEnumerator EatFood()
{
switch (interaction.InteractGameObject.gameObject.name)
{
case "Mushroom1":
stamina.Add(10f);
Debug.Log("스태미나가 회복 됬습니다.");
yield return null;
break;
case "Mushroom2":
health.Add(healing);
Debug.Log("체력이 회복됬습니다.");
yield return null;
break;
case "Mushroom3":
health.Subtract(poisondamage);
Debug.Log("독 버섯을 먹었습니다.");
yield return null;
break;
case "MushroomLarge":
controller.moveSpeed = 10f;
Debug.Log("이동속도가 5초 동안 매우 빨라집니다.");
yield return new WaitForSecondsRealtime(5f);
controller.moveSpeed = 5f;
break;
}
}