From 18d6b012a6e9a74171e2ac484fc28d68c372a4bd Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Wed, 18 Oct 2017 00:08:07 +0200 Subject: Added another tower, tweaked prices, by some reason waves are not always spawning... --- td/Assets/Scripts/player.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'td/Assets/Scripts/player.cs') 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 (); - script.Player = this; + float thisTowerPrice = towerType.gameObject.GetComponent().TowerPrice; + if (_playerMoney >= thisTowerPrice) { + GameObject tower = Instantiate(towerType, new Vector3(0, 0, 0), Quaternion.identity, + transform.Find("towers").transform); + Tower script = tower.GetComponent(); + script.Player = this; + } + else { + TxtNoMoney.SetActive(true); + } } public void GameStateWatcher() { -- cgit v1.2.3