Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class NewEnemySpawning : MonoBehaviour
- {
- [SerializeField]private GameObject _enemyUnit;
- private List<GameObject> _spawnedEnemies;
- //private GameObject[] _spawnedEnemies;
- [SerializeField]private GameObject _timer;
- public float _waveCoolDown;
- public float _spawnCoolDown;
- public int _currentWaveEnemyCount;
- [SerializeField]private int _maxEnemiesPerWave = 6;
- void Start()
- {
- //_spawnedEnemies = new GameObject[_maxEnemiesPerWave];
- StartCoroutine(SpawnWave());
- //getting waveCoolDown amount
- _waveCoolDown = _timer.GetComponent<NewWaveTimer>()._waveTimeLeft;
- }
- IEnumerator SpawnWave()
- {
- //let it loop
- while (true)
- {
- //spawning enemies with time in between
- for (int i = 0; i <= _maxEnemiesPerWave; i++)
- {
- //_spawnedEnemies[_maxEnemiesPerWave] = (GameObject)Instantiate(_enemyUnit, transform.position, Quaternion.identity);
- GameObject _spawnedEnemy = (GameObject)Instantiate(_enemyUnit, transform.position, Quaternion.identity);
- _spawnedEnemies.Add(_spawnedEnemy);
- _currentWaveEnemyCount++;
- //portal shake?
- yield return new WaitForSeconds(_spawnCoolDown);
- }
- //if there are no enemies then a new wave begins immediately
- if (_currentWaveEnemyCount > 0)
- {
- _waveCoolDown = 0;
- }
- _maxEnemiesPerWave++;
- yield return new WaitForSeconds(_waveCoolDown);
- }
- }
- //when enemies get destroyed the count goes down -- destruction of enemies is done in another class
- public int CurrentWaveEnemyCount
- {
- get { return _currentWaveEnemyCount; }
- set { _currentWaveEnemyCount = value; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement