public override void ConfigureSlot(Item item, SlotManager slotManager) { base.ConfigureSlot(item, slotManager); // Replace the default action with buy. slotManager.ResetButtonAction(); slotManager.SetButtonText("Buy"); slotManager.SetName($"{item.GetName()} - {item.GetValue()/100f:c2}"); slotManager.IsButtonEnabled(_playerBalance.GetBalance() >= item.GetValue()); slotManager.SetBuyItem(_playerInventory, _playerBalance, item, this); }
public static void Buy(Inventory playerInventory, PlayerBalance playerBalance, Item itemToBuy, ShopDisplay shopDisplay) { // Check if the player can afford the item. var itemValue = itemToBuy.GetValue(); var canAfford = playerBalance.GetBalance() >= itemValue; // Return if the item is too expensive. if (!canAfford) { return; } // Add the item to the inventory. playerInventory.AddItem(itemToBuy); // Remove the price of the item from the playerBalance.ChangeBalance(-itemValue); // Regenerate the ui. shopDisplay.Regenerate(); }
private void Update() { _text.text = $"{_playerBalance.GetBalance() / 100f:c2}"; }