-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildMode.cs
More file actions
80 lines (68 loc) · 2.07 KB
/
BuildMode.cs
File metadata and controls
80 lines (68 loc) · 2.07 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(MapGenerator))]
public class BuildMode : MonoBehaviour {
public static BuildMode Instance { get; protected set; }
public GameObject buildPanel;
public GameObject[] objects;
public Material ghostGreen;
public Material ghostRed;
public int storeNumber;
GameObject ghost;
TileMarkerScript tileMarkerScript;
bool buildPanelActive;
// Use this for initialization
void Start () {
if (Instance == null) {
Instance = this;
}
else {
Debug.LogError("Only one instance of BuildScript can be created");
}
buildPanelActive = buildPanel.activeSelf;
tileMarkerScript = GameObject.Find("TileMarker").GetComponent<TileMarkerScript>();
for (int i = 0; i < objects.Length; i++)
{
if (objects[i].name == "Store")
{
storeNumber = i;
Debug.Log("storeNumber " + storeNumber);
break;
}
}
}
public void OnBuildButtonClick()
{
buildPanel.SetActive(!buildPanelActive);
buildPanelActive = buildPanel.activeSelf;
if (buildPanelActive == false)
{
Destroy(ghost);
tileMarkerScript.enabled = false;
}
}
public void OnTileButtonClick(int number)
{
Destroy(ghost);
tileMarkerScript.enabled = true;
tileMarkerScript.currentObject = number;
}
public void OnHouseButtonClick(int number)
{
tileMarkerScript.enabled = false;
Destroy(ghost);
if (number < objects.Length)
{
ghost = Instantiate(objects[number]);
ghost.AddComponent<GhostScript>();
ghost.GetComponent<GhostScript>().number = number;
} else
{
Debug.LogError("House with number " + number + " not found.");
}
}
public void BuildRoad(Vector2 coord)
{
MapController.Instance.ChangeTile(coord, "Road");
}
}