Пример #1
0
    public void BuyItem()
    {
        if (_recentSlot.Ingredient != null)
        {
            if (!_recentSlot.CanSell)
            {
                _cancelAudio?.Play();
                return;
            }

            if (fileUtility.SaveObject.gold >= _recentSlot.Ingredient.Cost)
            {
                _purchaseAudio?.Play();

                _recentSlot.Ingredient.IncreaseQuantity(1);

                fileUtility.SaveObject.gold -= _recentSlot.Ingredient.Cost;

                _feedbackText.text = "BOUGHT: " + _recentSlot.Ingredient.Name +
                                     "\nYou have: " + fileUtility.SaveObject.gold + " gold" +
                                     "\nYou have: " + _recentSlot.Ingredient.Quantity + " " + _recentSlot.Ingredient.Name;

                _recentSlot.BoughtItem();
                fileUtility.Save();
            }
            else
            {
                _cancelAudio?.Play();

                _feedbackText.text = "Cannot afford a " + _recentSlot.Ingredient.Name + "," +
                                     "\nYou have: " + fileUtility.SaveObject.gold + " gold" +
                                     "\nYou need: " + _recentSlot.Ingredient.Cost + " gold";
            }
        }
    }