示例#1
0
    private bool AddItemToInventory()
    {
        //  Get Player
        Player player = FindObjectOfType <Player>();

        //  Hacky edge case for fuel
        if (MyType == InventoryItem.Type.Fuel || MyType == InventoryItem.Type.RefinedFuel)
        {
            //  Add fuel to player
            GameManager.FuelType fuelType;
            if (MyType == InventoryItem.Type.Fuel)
            {
                fuelType = GameManager.FuelType.Regular;
            }
            else
            {
                fuelType = GameManager.FuelType.Refined;
            }

            FuelTank fuelTank = player.GetEmptiestFuelTankOfType(fuelType);
            if (fuelTank == null)
            {
                return(false);
            }

            float leftover = fuelTank.addFuel(5, fuelType);

            //  If all fuel returned then return false
            if (leftover == 5)
            {
                return(false);
            }

            //  Otherwise return true
            return(true);
        }

        return(player.inventory.AddItem(new InventoryItem(MyType)));
    }