-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTowerButtonUI.cs
More file actions
41 lines (34 loc) · 1.02 KB
/
TowerButtonUI.cs
File metadata and controls
41 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class TowerButtonUI : MonoBehaviour
{
public TowerData tower;
public TextMeshProUGUI towerNameText;
public TextMeshProUGUI towerCostText;
public Image towerIcon;
private Button button;
void onEnable (){
GameManager.instance.onMoneyChanged.AddListener(OnMoneyChanged);
}
void onDisable (){
GameManager.instance.onMoneyChanged.RemoveListener(OnMoneyChanged);
}
void Awake (){
button = GetComponent<Button>();
}
void Start (){
towerNameText.text = tower.displayName;
towerCostText.text = $"{tower.cost}";
towerIcon.sprite = tower.icon;
OnMoneyChanged();
}
public void OnClick (){
GameManager.instance.towerPlacement.SelectTowerToPlace(tower);
}
void OnMoneyChanged (){
button.interactable = GameManager.instance.money >= tower.cost;
}
}