-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.cs
39 lines (29 loc) · 896 Bytes
/
Button.cs
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
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Button : MonoBehaviour {
public GameObject defenderPrefab;
public static GameObject selectedDefender;
private Text costText;
private Button[] buttonArray;
// Use this for initialization
void Start () {
buttonArray = GameObject.FindObjectsOfType<Button>();
DisplayCostText();
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
foreach(Button thisButton in buttonArray){
thisButton.GetComponent<SpriteRenderer>().color = Color.black;
}
GetComponent<SpriteRenderer>().color = Color.white;
selectedDefender = defenderPrefab;
}
void DisplayCostText(){
costText = GetComponentInChildren<Text>();
if(!costText) {Debug.LogWarning(name + " has no cost text");}
costText.text = defenderPrefab.GetComponent<Defender>().starCost.ToString();
}
}