aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/player.cs
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2017-10-18 00:08:07 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2017-10-18 00:08:07 +0200
commit18d6b012a6e9a74171e2ac484fc28d68c372a4bd (patch)
treeb04b616115a7cb8c9d0498fb6e766556a8a39c23 /td/Assets/Scripts/player.cs
parent12b8646159169c082ae7197ed7af4bbcf1d9e2cb (diff)
downloadTD-18d6b012a6e9a74171e2ac484fc28d68c372a4bd.tar.gz
TD-18d6b012a6e9a74171e2ac484fc28d68c372a4bd.zip
Added another tower, tweaked prices, by some reason waves are not always spawning...
Diffstat (limited to 'td/Assets/Scripts/player.cs')
-rw-r--r--td/Assets/Scripts/player.cs15
1 files changed, 12 insertions, 3 deletions
diff --git a/td/Assets/Scripts/player.cs b/td/Assets/Scripts/player.cs
index a1e9d81..5fd9725 100644
--- a/td/Assets/Scripts/player.cs
+++ b/td/Assets/Scripts/player.cs
@@ -6,6 +6,8 @@ public class Player : MonoBehaviour {
public int StartingMoney;
public MainGui MainGui;
+ public GameObject TxtNoMoney; // HACK Move this into MainGui, and make a callable function or something! This is just bodging.
+
private int _gameState;
private GameObject[] _towers;
private int _playerMoney;
@@ -74,9 +76,16 @@ public class Player : MonoBehaviour {
#endregion
public void SpawnTower(GameObject towerType) {
- GameObject tower = Instantiate (towerType, new Vector3 (0, 0, 0), Quaternion.identity, transform.Find ("towers").transform);
- Tower script = tower.GetComponent <Tower>();
- script.Player = this;
+ float thisTowerPrice = towerType.gameObject.GetComponent<Tower>().TowerPrice;
+ if (_playerMoney >= thisTowerPrice) {
+ GameObject tower = Instantiate(towerType, new Vector3(0, 0, 0), Quaternion.identity,
+ transform.Find("towers").transform);
+ Tower script = tower.GetComponent<Tower>();
+ script.Player = this;
+ }
+ else {
+ TxtNoMoney.SetActive(true);
+ }
}
public void GameStateWatcher() {