Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

wave spawner difficulty increase

$
0
0
there's the script using UnityEngine; using System.Collections; using System.Collections.Generic; public class WaveSpawner : MonoBehaviour { public enum SpawnState { Spawning, waiting, counting}; [System.Serializable] public class Wave { public string name; public Transform enemy; public int count; public float rate; } public List waves = new List(); private int nextWave = 0; public Transform[] spawnPoints; private SpawnState state = SpawnState.counting; public float timeBetweenWaves = 5f; public float waveCountdown; private float searchCountdown = 1f; public Transform normalEnemy; public int currentCount; public float currentRate; void Start() { waveCountdown = timeBetweenWaves; currentCount = 2; currentRate = 3; } void Update() { if (state == SpawnState.waiting) { if (EnemyIsAlive() == false) { WaveCompleted(); } else { return; } } if (waveCountdown <= 0) { if (state != SpawnState.Spawning) { StartCoroutine(SpawnWave(waves[nextWave])); } } else { waveCountdown -= Time.deltaTime; } } void WaveCompleted() { state = SpawnState.counting; waveCountdown = timeBetweenWaves; //TODO add more waves // if (nextWave + 1 > waves.Count - 1) // { currentCount += 2; CreateWave(normalEnemy, currentCount, currentRate); // Debug.Log("All Waves Complete"); //} nextWave++; } private void CreateWave(Transform Enemy, int Count, float rate) { Wave wave = new Wave(); currentCount = wave.count; currentRate = wave.rate; wave.name = "autoGenerated Wave"; wave.count = Count; wave.rate = rate; wave.enemy = Enemy; waves.Add(wave); } bool EnemyIsAlive() { searchCountdown -= Time.deltaTime; if (searchCountdown <= 0f) { searchCountdown = 1f; if (GameObject.FindGameObjectWithTag("Enemy") == null) { return false; } } return true; } IEnumerator SpawnWave(Wave _wave) { state = SpawnState.Spawning; // currentCount = _wave.count; //currentRate = _wave.rate; for (int i = 0; i < _wave.count; i++) { SpawnEnemy(_wave.enemy); yield return new WaitForSeconds(1 / _wave.rate); } state = SpawnState.waiting; yield break; } void SpawnEnemy(Transform _enemy) { Transform _sp = spawnPoints[Random.Range(0, spawnPoints.Length)]; Instantiate(_enemy, _sp.position, _sp.rotation); } } why doesn't it work?

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>