Building shop functional and Building states are saved online
This commit is contained in:
40
Assets/Game/Scripts/ShopBuildingButton.cs
Normal file
40
Assets/Game/Scripts/ShopBuildingButton.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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 = false;
|
||||
foreach (BuildingState buildingState in DBmanager.buildingStates){
|
||||
if(buildingState.id == buildingData.buildingName){
|
||||
exists=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
gameObject.SetActive(!exists);
|
||||
btn.interactable = (DBmanager.Coins > buildingData.levels[0].price);
|
||||
txt.text = buildingData.levels[0].price.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user