Animals can now be bought in AnimalShop
if bought they will be placed somewhere random on the map
This commit is contained in:
parent
acd602c85a
commit
441ffb900a
34 changed files with 2387 additions and 265 deletions
51
Assets/Scripts/Shop/ItemShopSlot.cs
Normal file
51
Assets/Scripts/Shop/ItemShopSlot.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using TMPro;
|
||||
|
||||
namespace Shop {
|
||||
public class ItemShopSlot : ElementStorageSlot<Item> {
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI costText;
|
||||
|
||||
private ItemShop _itemShop;
|
||||
private Inventory _inventory;
|
||||
private PlayerController _playerController;
|
||||
|
||||
private void Start() {
|
||||
_itemShop = ItemShop.instance;
|
||||
_inventory = Inventory.instance;
|
||||
_playerController = PlayerController.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Shop Slot
|
||||
*/
|
||||
public override void ClearSlot() {
|
||||
nameText.text = "";
|
||||
costText.text = "";
|
||||
amountText.text = "";
|
||||
base.ClearSlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called when the Shop Slot is clicked
|
||||
*/
|
||||
public override void UseElement() {
|
||||
if(Element) {
|
||||
if(_playerController.Money >= Element.price) {
|
||||
if(Element) {
|
||||
_playerController.ChangeMoney(-Element.price);
|
||||
_itemShop.itemWasBought = true;
|
||||
// Debug.Log("Buying Item: " + Element.displayName);
|
||||
}
|
||||
|
||||
_inventory.AddElement(Element, 1);
|
||||
_itemShop.RemoveElement(Element, 1);
|
||||
} else {
|
||||
// Debug.Log("Not enough money to buy Item.");
|
||||
}
|
||||
|
||||
_itemShop.onElementChangedCallback?.Invoke();
|
||||
_inventory.onElementChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue