Exemplo n.º 1
0
    public void OnPointerDown(PointerEventData data)
    {
        float distance = Vector3.Distance(player.transform.position, gameObject.transform.position);

        if (distance <= range)
        {
            if (PlayerData.player.GetCurrentFood() != null && PlayerData.player.GetCounterFood(counterNum) == null)
            {
                // place ONE food on counter
                FoodObject food = PlayerData.player.GetCurrentFood();
                food.subOneQ();
                PlayerData.player.SetCurrentFood(food);

                FoodObject counter = new FoodObject(food);
                counter.setQuantity(1);
                PlayerData.player.SetCounterFood(counterNum, counter);
                Refresh();
            }
            else if (PlayerData.player.GetCurrentFood() != null && PlayerData.player.GetCounterFood(counterNum) != null)
            {
                // stack food back if same name
                FoodObject food = PlayerData.player.GetCurrentFood();
                if (PlayerData.player.GetCounterFood(counterNum).getName() == food.getName())
                {
                    food.addOneQ();
                    PlayerData.player.SetCurrentFood(food);
                    PlayerData.player.SetCounterFood(counterNum, null);
                    Refresh();
                }
            }
            else if (PlayerData.player.GetCurrentFood() == null && PlayerData.player.GetCounterFood(counterNum) != null)
            {
                // remove food from counter
                PlayerData.player.SetCurrentFood(PlayerData.player.GetCounterFood(counterNum));
                PlayerData.player.SetCounterFood(counterNum, null);
                Refresh();
            }
        }
    }