35 lines
934 B
C#
Executable File
35 lines
934 B
C#
Executable File
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class ShopBuildingButton : MonoBehaviour
|
|
{
|
|
public BuildingData buildingData;
|
|
public Button btn;
|
|
public TMP_Text txt;
|
|
void Start()
|
|
{
|
|
DBmanager.OnStateChanged.AddListener(refresh);
|
|
refresh();
|
|
btn.onClick.AddListener(OnClick);
|
|
}
|
|
|
|
void OnClick(){
|
|
btn.interactable=false;
|
|
}
|
|
|
|
void OnValidate(){
|
|
if(btn==null){btn = GetComponent<Button>();}
|
|
if(txt==null){txt=GetComponentInChildren<TMP_Text>();}
|
|
}
|
|
|
|
public void refresh(){
|
|
bool exists = DBmanager.buildingStates.ContainsKey(buildingData.buildingName);
|
|
gameObject.SetActive(!exists);
|
|
btn.interactable = (DBmanager.Coins > buildingData.levels[0].price);
|
|
txt.text = buildingData.levels[0].price.ToString();
|
|
}
|
|
}
|