Item shop functioning
This commit is contained in:
47
Assets/Game/Scripts/ItemShop.cs
Normal file
47
Assets/Game/Scripts/ItemShop.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class ItemShop : MonoBehaviour
|
||||
{
|
||||
public ShopItemData selectedItem;
|
||||
|
||||
public Image itemImage;
|
||||
public TMP_Text itemTxt;
|
||||
public TMP_Text levelTxt;
|
||||
|
||||
public TMP_Text statTxt;
|
||||
public TMP_Text priceTxt;
|
||||
public TMP_Text gemTxt;
|
||||
|
||||
public Button buyBtn;
|
||||
|
||||
void Start(){
|
||||
SelectShopItem(selectedItem);
|
||||
}
|
||||
|
||||
public void SelectShopItem(ShopItemData selected){
|
||||
selectedItem = selected;
|
||||
|
||||
if(selectedItem==null){Debug.LogError("Null shop item selected, Please check this"); return;}
|
||||
|
||||
itemImage.sprite = selectedItem.image;
|
||||
itemTxt.text = selectedItem.itemName;
|
||||
statTxt.text = selectedItem.stat.ToString();
|
||||
priceTxt.text = selectedItem.price.ToString();
|
||||
gemTxt.text = selectedItem.gems.ToString();
|
||||
|
||||
buyBtn.interactable = selectedItem.price < DBmanager.Coins && selectedItem.gems < DBmanager.Gems;
|
||||
}
|
||||
|
||||
public void BuySelected(){
|
||||
if(selectedItem == null){
|
||||
Debug.LogError("Cant buy, No item is selected");
|
||||
return;
|
||||
}
|
||||
|
||||
DBmanager.SetCoins(DBmanager.Coins - selectedItem.price);
|
||||
DBmanager.SetGems(DBmanager.Gems- selectedItem.gems);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user