diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-06 16:04:38 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-06 16:04:38 +0200 |
commit | e13fd4cf1fc0ad9eff857295fd5abc15ab01462c (patch) | |
tree | 91786e1557ef801a64e059857dc0ad71c1d281df /td/Assets/Scripts/waveSpawner.cs | |
parent | c5a786326fab8850342005a1eb4da9653c4642c8 (diff) | |
download | TD-e13fd4cf1fc0ad9eff857295fd5abc15ab01462c.tar.gz TD-e13fd4cf1fc0ad9eff857295fd5abc15ab01462c.zip |
Startet på tårn, fiksa dev-mode, laga stats UI
Diffstat (limited to 'td/Assets/Scripts/waveSpawner.cs')
-rw-r--r-- | td/Assets/Scripts/waveSpawner.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/td/Assets/Scripts/waveSpawner.cs b/td/Assets/Scripts/waveSpawner.cs new file mode 100644 index 0000000..c3fada3 --- /dev/null +++ b/td/Assets/Scripts/waveSpawner.cs @@ -0,0 +1,76 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class waveSpawner : MonoBehaviour { + + public static int EnemiesAlive = 0; + + public Wave[] waves; + + public Transform spawnPoint; + + public float timeBetweenWaves = 5f; + private float countdown = 2f; + + public Text waveCountdownText; + + + private int waveIndex = 0; + + void Update () + { + if (EnemiesAlive > 0) + { + return; + } + + if (waveIndex == waves.Length) + { + // WIN LEVEL!!! + this.enabled = false; + } + + if (countdown <= 0f) + { + StartCoroutine(SpawnWave()); + countdown = timeBetweenWaves; + return; + } + + countdown -= Time.deltaTime; + + countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity); + + //waveCountdownText.text = string.Format("{0:00.00}", countdown); + } + + IEnumerator SpawnWave () + { + Wave wave = waves[waveIndex]; + + EnemiesAlive = wave.count; + + for (int i = 0; i < wave.count; i++) + { + SpawnEnemy(wave.enemy); + yield return new WaitForSeconds(1f / wave.rate); + } + + waveIndex++; + } + + void SpawnEnemy (GameObject enemy) + { + Instantiate(enemy, spawnPoint.position, spawnPoint.rotation); + } + +} + +[System.Serializable] +public class Wave { + public GameObject enemy; + public int count; + public float rate; +}
\ No newline at end of file |