오늘은 손님이 요청한 음식과 플레이어가 서빙한 음식이 똑같으면

손님이 점프하는 애니메이션을 재생하고,

서빙한 음식이 사라지고,

식당을 나가는 것 까지 구현했다.

 

음식이 놓일 자리를 관리해주는

FoodPlace 클래스를 만들었다.

 

FoodPlace에 음식이 놓이면 그 자리에 있는 손님이 요청한 음식과 비교한다.

public class FoodPlace : MonoBehaviour
{
    private const float _foodDestroyTime = 2.0f;
    
    private CustomerController _currentCustomer;
    public CustomerController CurrentCustomer
    {
        get { return _currentCustomer; }
        set { _currentCustomer = value; }
    }
    
    private CookedFood _currentFood;
    public CookedFood CurrentFood
    {
        get { return _currentFood; }
        set
        {
            _currentFood = value;

            if (_currentCustomer != null && _currentFood != null)
            {
                if (_currentCustomer.TargetFood.name == _currentFood.FoodName)
                {
                    MatchWithCustomer();
                }
            }
        }
    }

    public event Action OnCustomerGetFood;

    private void MatchWithCustomer()
    {
        // TODO: Get Gold

        OnCustomerGetFood.Invoke();

        StartCoroutine(DestoryCurrentFood(_currentFood.gameObject));
        
        _currentFood = null;
        _currentCustomer = null;
    }

    IEnumerator DestoryCurrentFood(GameObject food)
    {
        yield return new WaitForSeconds(_foodDestroyTime);

        Destroy(food);
    }
}