Foerming/Assets/Scripts/Shop.cs
d-hain ba9be3d96b you can now sell Items with Right Mouse Click on an InventorySlot for the Item.SellPrice
and it gets put into the Shop for full price

renamed Item.cost to Item.price
2022-06-08 22:52:28 +02:00

49 lines
No EOL
1.3 KiB
C#

using UnityEngine;
public class Shop : ItemStorage {
#region Singleton
public static Shop instance;
private void Awake() {
if(instance != null) {
Debug.LogWarning("More than one instance of Shop found");
}
instance = this;
}
#endregion
public bool itemWasBought;
private PlayerController _playerController;
private Inventory _inventory;
private Item _lastBoughtItem;
private int _lastBoughtItemAmount;
/**
* Calls ItemStorage.RemoveItem() and sets 2 Variables to remember the last bought item
*/
public override void RemoveItem(Item item, int amount) {
base.RemoveItem(item, amount);
if(itemWasBought){
_lastBoughtItem = item;
_lastBoughtItemAmount = amount;
}
}
public void UndoLastPurchase() {
if(itemWasBought){
_inventory = Inventory.instance;
_playerController = PlayerController.instance;
if(_lastBoughtItem) {
_playerController.ChangeMoney(_lastBoughtItem.price);
_inventory.RemoveItem(_lastBoughtItem, _lastBoughtItemAmount);
AddItem(_lastBoughtItem, _lastBoughtItemAmount);
itemWasBought = false;
}
}
}
}