aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'td/Assets/Scripts')
-rw-r--r--td/Assets/Scripts/FlashColor.cs58
-rw-r--r--td/Assets/Scripts/FlashColor.cs.meta12
-rw-r--r--td/Assets/Scripts/player.cs15
-rw-r--r--td/Assets/Scripts/tower.cs3
-rw-r--r--td/Assets/Scripts/waveSpawner.cs2
5 files changed, 85 insertions, 5 deletions
diff --git a/td/Assets/Scripts/FlashColor.cs b/td/Assets/Scripts/FlashColor.cs
new file mode 100644
index 0000000..b5da678
--- /dev/null
+++ b/td/Assets/Scripts/FlashColor.cs
@@ -0,0 +1,58 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class FlashColor : MonoBehaviour {
+
+ public Color Color1;
+ public Color Color2;
+ public float TransitionTime;
+ public bool HideAfterCountdown;
+ public float DisplayTime;
+
+ private Text _text;
+ public float TimeSinceBorn;
+
+ void Start() {
+ TimeSinceBorn = 0;
+ _text = gameObject.GetComponent<Text>();
+ StartCoroutine("Flash");
+ }
+
+ void OnEnable() {
+ TimeSinceBorn = 0;
+ _text = gameObject.GetComponent<Text>();
+ StartCoroutine("Flash");
+ }
+
+ void Update () {
+ if (HideAfterCountdown) {
+ TimeSinceBorn += Time.deltaTime;
+ if (TimeSinceBorn >= DisplayTime) {
+ gameObject.SetActive(false);
+ }
+ }
+ }
+
+ IEnumerator Flash() {
+ while (true) {
+ float elapsedTime = 0.0f;
+ while (elapsedTime < TransitionTime) {
+ elapsedTime += Time.deltaTime;
+ _text.color = Color.Lerp(Color1, Color2, (elapsedTime / TransitionTime));
+ yield return null;
+ }
+
+ elapsedTime = 0.0f;
+ while (elapsedTime < TransitionTime) {
+ elapsedTime += Time.deltaTime;
+ _text.color = Color.Lerp(Color2, Color1, (elapsedTime / TransitionTime));
+ yield return null;
+ }
+ yield return null;
+ }
+ }
+
+
+}
diff --git a/td/Assets/Scripts/FlashColor.cs.meta b/td/Assets/Scripts/FlashColor.cs.meta
new file mode 100644
index 0000000..bfdfe59
--- /dev/null
+++ b/td/Assets/Scripts/FlashColor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e8fe077b8c39e47e9942d71e7cfb113b
+timeCreated: 1508273394
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
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() {
diff --git a/td/Assets/Scripts/tower.cs b/td/Assets/Scripts/tower.cs
index 004605b..eb1c552 100644
--- a/td/Assets/Scripts/tower.cs
+++ b/td/Assets/Scripts/tower.cs
@@ -8,6 +8,7 @@ public class Tower : MonoBehaviour {
public float TurnSpeed; // How fast the turret should rotate. Set in designer (tower prefab)
[Range(0, 10)]
public float TowerRange; // How large the range of the tower is. this is the diameter. Set in designer (tower prefab)
+ public float TowerRangeMultiplier;
public GameObject ProjectilePrefab;
public Transform FirePoint;
[Header("Materials")]
@@ -29,7 +30,7 @@ public class Tower : MonoBehaviour {
void Start () {
_placementIndicator = transform.GetChild (0).gameObject;
_placementIndicatorRenderer = _placementIndicator.GetComponent<Renderer> ();
- _placementIndicator.transform.localScale = new Vector3 (TowerRange*7, 0.00000001f, TowerRange*7);
+ _placementIndicator.transform.localScale = new Vector3 (TowerRange*7*TowerRangeMultiplier, 0.00000001f, TowerRange*7*TowerRangeMultiplier);
_groundPlane = new Plane (Vector3.up, new Vector3(0f, _groundYpoint, 0f));
}
diff --git a/td/Assets/Scripts/waveSpawner.cs b/td/Assets/Scripts/waveSpawner.cs
index 6444cfd..4d5f95d 100644
--- a/td/Assets/Scripts/waveSpawner.cs
+++ b/td/Assets/Scripts/waveSpawner.cs
@@ -55,7 +55,7 @@ public class WaveSpawner : MonoBehaviour {
_countdown = TimeBetweenWaves;
return;
}
-
+ Debug.Log(_countdown);
_countdown -= Time.deltaTime;
_countdown = Mathf.Clamp(_countdown, 0f, Mathf.Infinity);
//waveCountdownText.text = string.Format("{0:00.00}", countdown);