UPF/Assets/Game/Scripts/ItemShop.cs
2022-05-06 00:36:18 +05:30

48 lines
1.3 KiB
C#

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);
}
}