Repository navigation
Expand file tree
/
Copy pathTowerScript.cs
More file actions
168 lines (140 loc) · 6.79 KB
/
Copy pathTowerScript.cs
File metadata and controls
168 lines (140 loc) · 6.79 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TowerScript : MonoBehaviour
{
public float damageDone;
public int moneySpent;
public int[] upgradeIndex;
public GameObject rangeDisplay;
Button button1;
Text button1Text;
Button button2;
Text button2Text;
public TowerUpgradesSO towerUpgrades;
public ButtonScript btnScript;
public GameController gameCon;
void Start()
{
//Get all tower stats from GameController. Save space by giving towers only their stats instead of the stats of every tower type.
GetComponent<BoxCollider2D>().size = new Vector2(GetComponent<Shooting>().towerStats.colliderLength, GetComponent<Shooting>().towerStats.colliderHeight);
GetComponent<BoxCollider2D>().offset = new Vector2(GetComponent<Shooting>().towerStats.colliderOffsetX, GetComponent<Shooting>().towerStats.colliderOffsetY);
gameCon = GameObject.Find("GameController").GetComponent<GameController>();
upgradeIndex = new int[2];
upgradeIndex[1] = 5;
gameCon.GetComponent<GameController>().activePhantomTower = -1;
button1 = GameObject.Find("Upgrade1").GetComponent<Button>();
button1Text = GameObject.Find("Upgrade1Text").GetComponent<Text>();
button2 = GameObject.Find("Upgrade2").GetComponent<Button>();
button2Text = GameObject.Find("Upgrade2Text").GetComponent<Text>();
moneySpent += GetComponent<Shooting>().towerStats.cost;
}
void selectTower()
{
newRangeDisplays();
openUpgradeMenu();
}
void newRangeDisplays()
{
GameObject[] rangeDisplays = GameObject.FindGameObjectsWithTag("RangeDisplay");
foreach (GameObject i in rangeDisplays)
{
Destroy(i);
}
var rangeDisplayVar = Instantiate(rangeDisplay, gameObject.transform.position, Quaternion.identity);
rangeDisplayVar.transform.localScale = new Vector2(GetComponent<Shooting>().towerStats.range, GetComponent<Shooting>().towerStats.range);
}
void changeButtonStuff()
{
if (upgradeIndex[0] == 5 || (upgradeIndex[0] == 2 && upgradeIndex[1] - 5 >= 3))
{
button1.GetComponent<UpgradeButtonScript>().maxed = true;
}
else
{
button1.GetComponent<UpgradeButtonScript>().maxed = false;
button1.GetComponent<UpgradeButtonScript>().cost = towerUpgrades.cost[upgradeIndex[0]];
button1.GetComponent<UpgradeButtonScript>().tooltipText = towerUpgrades.descriptions[upgradeIndex[0]];
button1.GetComponentInChildren<Text>().text = ("Buy for: " + towerUpgrades.cost[upgradeIndex[0]] + "\n");
}
if (upgradeIndex[1] - 5 == 5 || (upgradeIndex[1] - 5 == 2 && upgradeIndex[0] >= 3))
{
button2.GetComponent<UpgradeButtonScript>().maxed = true;
}
else
{
button2.GetComponent<UpgradeButtonScript>().maxed = false;
button2.GetComponent<UpgradeButtonScript>().cost = towerUpgrades.cost[upgradeIndex[1]];
button2.GetComponent<UpgradeButtonScript>().tooltipText = towerUpgrades.descriptions[upgradeIndex[1]];
button2.GetComponentInChildren<Text>().text = ("Buy for: " + towerUpgrades.cost[upgradeIndex[1]] + "\n");
}
}
void openUpgradeMenu()
{
changeButtonStuff();
GameObject.Find("UpgradeMenu").GetComponent<UpgradeMenuScript>().activeTower = this.gameObject;
Vector3 upgradeMenuV = gameCon.upgradeMenu.transform.position;
upgradeMenuV.y = -51;
gameCon.upgradeMenu.transform.position = upgradeMenuV;
}
public void upgrade(int path)
{
if (gameCon.GetComponent<GameController>().money >= towerUpgrades.cost[upgradeIndex[path]])
{
gameCon.GetComponent<GameController>().money -= towerUpgrades.cost[upgradeIndex[path]];
moneySpent += towerUpgrades.cost[upgradeIndex[path]];
if (towerUpgrades.range[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.range *= (towerUpgrades.range[upgradeIndex[path]] + 1);
newRangeDisplays();
}
if (towerUpgrades.damage[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.damage *= (towerUpgrades.damage[upgradeIndex[path]] + 1);
}
if (towerUpgrades.frequency[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.frequency *= (towerUpgrades.frequency[upgradeIndex[path]] + 1);
GetComponent<Shooting>().animator.speed = GetComponent<Shooting>().towerStats.frequency;
}
if (towerUpgrades.pierce[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.pierce = Mathf.FloorToInt(GetComponent<Shooting>().towerStats.pierce * (towerUpgrades.pierce[upgradeIndex[path]] + 1));
}
if (towerUpgrades.speed[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.speed *= (towerUpgrades.speed[upgradeIndex[path]] + 1);
}
if (towerUpgrades.lifetime[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.lifetime *= (towerUpgrades.lifetime[upgradeIndex[path]] + 1);
}
if (towerUpgrades.numOfShots[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.numOfShots += (towerUpgrades.numOfShots[upgradeIndex[path]]);
}
if (towerUpgrades.shotAngle[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.shotAngle += (towerUpgrades.shotAngle[upgradeIndex[path]]);
}
if (towerUpgrades.rotationSpeed[upgradeIndex[path]] != 0)
{
if(Mathf.Abs(towerUpgrades.rotationSpeed[upgradeIndex[path]]) >= 1000)
{
GetComponent<Shooting>().towerStats.rotationSpeed += (towerUpgrades.rotationSpeed[upgradeIndex[path]] / 1000);
}
else
{
GetComponent<Shooting>().towerStats.rotationSpeed *= (towerUpgrades.rotationSpeed[upgradeIndex[path]] + 1);
}
}
if (towerUpgrades.slowAmount[upgradeIndex[path]] != 0)
{
GetComponent<Shooting>().towerStats.slowAmount *= (towerUpgrades.slowAmount[upgradeIndex[path]] + 1);
}
upgradeIndex[path]++;
changeButtonStuff();
}
}
}