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/Prefabs/Enemies/Blue.prefab | Bin 7968 -> 8008 bytes td/Assets/Prefabs/Enemies/Enemy.prefab | Bin 8008 -> 8008 bytes td/Assets/Prefabs/Towers/Guy One.prefab | Bin 12040 -> 12096 bytes td/Assets/Prefabs/Towers/Guy Two.prefab | Bin 0 -> 12096 bytes td/Assets/Prefabs/Towers/Guy Two.prefab.meta | 9 +++++ td/Assets/Scenes/Level 1.unity | Bin 135364 -> 137852 bytes td/Assets/Scripts/FlashColor.cs | 58 +++++++++++++++++++++++++++ td/Assets/Scripts/FlashColor.cs.meta | 12 ++++++ td/Assets/Scripts/player.cs | 15 +++++-- td/Assets/Scripts/tower.cs | 3 +- td/Assets/Scripts/waveSpawner.cs | 2 +- 11 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 td/Assets/Prefabs/Towers/Guy Two.prefab create mode 100644 td/Assets/Prefabs/Towers/Guy Two.prefab.meta create mode 100644 td/Assets/Scripts/FlashColor.cs create mode 100644 td/Assets/Scripts/FlashColor.cs.meta (limited to 'td/Assets') diff --git a/td/Assets/Prefabs/Enemies/Blue.prefab b/td/Assets/Prefabs/Enemies/Blue.prefab index f98795d..8230836 100644 Binary files a/td/Assets/Prefabs/Enemies/Blue.prefab and b/td/Assets/Prefabs/Enemies/Blue.prefab differ diff --git a/td/Assets/Prefabs/Enemies/Enemy.prefab b/td/Assets/Prefabs/Enemies/Enemy.prefab index a17153b..59b494d 100644 Binary files a/td/Assets/Prefabs/Enemies/Enemy.prefab and b/td/Assets/Prefabs/Enemies/Enemy.prefab differ diff --git a/td/Assets/Prefabs/Towers/Guy One.prefab b/td/Assets/Prefabs/Towers/Guy One.prefab index 9736f41..658f770 100644 Binary files a/td/Assets/Prefabs/Towers/Guy One.prefab and b/td/Assets/Prefabs/Towers/Guy One.prefab differ diff --git a/td/Assets/Prefabs/Towers/Guy Two.prefab b/td/Assets/Prefabs/Towers/Guy Two.prefab new file mode 100644 index 0000000..f8f2ca3 Binary files /dev/null and b/td/Assets/Prefabs/Towers/Guy Two.prefab differ diff --git a/td/Assets/Prefabs/Towers/Guy Two.prefab.meta b/td/Assets/Prefabs/Towers/Guy Two.prefab.meta new file mode 100644 index 0000000..e1d28b6 --- /dev/null +++ b/td/Assets/Prefabs/Towers/Guy Two.prefab.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 93bab5a4ed54a48dab90fb8b6d89f329 +timeCreated: 1508277299 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/td/Assets/Scenes/Level 1.unity b/td/Assets/Scenes/Level 1.unity index 4f43cec..f4c4053 100644 Binary files a/td/Assets/Scenes/Level 1.unity and b/td/Assets/Scenes/Level 1.unity differ 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(); + StartCoroutine("Flash"); + } + + void OnEnable() { + TimeSinceBorn = 0; + _text = gameObject.GetComponent(); + 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 (); - 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() { 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 (); - _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); -- cgit v1.2.3