Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SpawnManager : MonoBehaviour
- {
- public GameObject _enemyPrefab;
- [SerializeField] private GameObject _bigEnemyPrefab;
- [SerializeField] private GameObject _enemyContainer;
- [SerializeField] private GameObject _enemyRLPrefab;
- [SerializeField] private GameObject _enemyLRPrefab;
- [SerializeField] private GameObject _bossFight;
- [SerializeField] private GameObject _laserAmmo;
- [SerializeField] private GameObject _clearWave;
- public List<GameObject> _smallEnemyGameObjectCountList = new List<GameObject>();
- public List<GameObject> _bigEnemyGameObjectCountList = new List<GameObject>();
- public List<GameObject> _enemyRLGameObjectCountList = new List<GameObject>();
- public List<GameObject> _enemyLRGameObjectCountList = new List<GameObject>();
- [SerializeField] private float _waitTime = 3f;
- [SerializeField] private float _wave2WaitTime = 6f;
- [SerializeField] private float _wave2WaitTime2 = 6f;
- [SerializeField] private float _bigEnemyWaitTime = 6f;
- [SerializeField] private GameObject[] _powerUps;
- [SerializeField] private AudioClip _enemyExplod;
- [SerializeField] private bool _stopSpawningOnPlayerDeath;
- [SerializeField] private bool _stopSpawningEnemy;
- [SerializeField] private bool _stopSpawningBigEnemy;
- [SerializeField] private bool _stopSpawningPowerUps;
- [SerializeField] private bool _stopSpawningRLEnemy;
- [SerializeField] private bool _stopSpawningLREnemy;
- [SerializeField] private bool _canSpawnSecondPowerUpWave;
- [SerializeField] private bool _isRLCoroutineStarted;
- [SerializeField] private bool _isLRCoroutineStarted;
- [SerializeField] private bool _isBossSpawn;
- UIManager _uiManager;
- EnemyBossScript _enemyBossScript;
- private void Start()
- {
- _uiManager = GameObject.Find("Canvas").GetComponent<UIManager>();
- if (_enemyBossScript != null)
- {
- _enemyBossScript = GameObject.Find("MainBodyBoss").GetComponent<EnemyBossScript>();
- }
- for (int i = 0; i < Random.Range(10, 30); i++)
- {
- _smallEnemyGameObjectCountList.Add(_enemyPrefab);
- }
- for (int i = 0; i < Random.Range(5, 9); i++)
- {
- _bigEnemyGameObjectCountList.Add(_bigEnemyPrefab);
- }
- for (int i = 0; i < Random.Range(10, 30); i++)
- {
- _enemyRLGameObjectCountList.Add(_enemyRLPrefab);
- }
- for (int i = 0; i < Random.Range(10, 30); i++)
- {
- _enemyLRGameObjectCountList.Add(_enemyLRPrefab);
- }
- }
- private void Update()
- {
- if (_smallEnemyGameObjectCountList.Count <= 5 && _bigEnemyGameObjectCountList.Count <= 5 && _isLRCoroutineStarted == false && _isRLCoroutineStarted == false)
- {
- StartCoroutine(StartSecondWaveRtoL());
- StartCoroutine(StartSecondWaveLtoRight());
- _isRLCoroutineStarted = true;
- _isLRCoroutineStarted = true;
- _stopSpawningPowerUps = true;
- //_canSpawnSecondPowerUpWave = true;// coroutine is already doing this when called....
- }
- if (_enemyLRGameObjectCountList.Count <= 3 && _enemyRLGameObjectCountList.Count <= 3 && _isBossSpawn == false)
- {
- StartCoroutine(SpawnBoss());
- _isBossSpawn = true;
- }
- }
- public void StartSpawn()
- {
- StartCoroutine(SpawnEnemyRoutine());
- StartCoroutine(SpawnPowerUpRoutine());
- StartCoroutine(SpawnBigEnemy());
- _uiManager.StartWaveOneText();
- }
- public void SubtractFromEnemyList()// being called from the enemyScript
- {
- _smallEnemyGameObjectCountList.Remove(_enemyPrefab);
- }
- public void SubtractFromBigEnemyList()// being called from the BigEnemyScript
- {
- _bigEnemyGameObjectCountList.Remove(_bigEnemyPrefab);
- }
- IEnumerator SpawnEnemyRoutine()
- {
- yield return new WaitForSeconds(6.0f);
- while (_stopSpawningOnPlayerDeath == false && _stopSpawningEnemy == false)
- {
- Vector3 spawnPosRando = new Vector3(Random.Range(-9.21f, 9.21f), 9f, 0);
- GameObject newEnemy = Instantiate(_enemyPrefab, spawnPosRando, Quaternion.identity);
- newEnemy.transform.parent = _enemyContainer.transform;
- yield return new WaitForSeconds(_waitTime);
- if (_smallEnemyGameObjectCountList.Count <=5)
- {
- _stopSpawningEnemy = true;
- }
- }
- }
- IEnumerator SpawnBigEnemy()
- {
- yield return new WaitForSeconds(10f);
- while (_stopSpawningOnPlayerDeath == false && _stopSpawningBigEnemy == false)
- {
- Vector3 spawnPosRandom = new Vector3(Random.Range(9.21f, -9.21f), 9f, 0);
- GameObject newBigEnemy = Instantiate(_bigEnemyPrefab, spawnPosRandom, Quaternion.identity);
- newBigEnemy.transform.parent = _enemyContainer.transform;
- yield return new WaitForSeconds(_bigEnemyWaitTime);
- if (_bigEnemyGameObjectCountList.Count <=5)
- {
- _stopSpawningBigEnemy = true;
- }
- }
- }
- IEnumerator SpawnPowerUpRoutine()
- {
- yield return new WaitForSeconds(6.0f);
- while (_stopSpawningOnPlayerDeath == false && _stopSpawningPowerUps == false)
- {
- Vector3 spawnPosRando = new Vector3(Random.Range(-9.21f, 9.21f), 9f, 0);
- int randompowerUpSpawn = Random.Range(0, 8);
- GameObject allThePowerUps = Instantiate(_powerUps[randompowerUpSpawn], spawnPosRando, Quaternion.identity);
- yield return new WaitForSeconds(Random.Range(3f, 10f));
- }
- }
- //*************Start Second Wave / PowerUps*************//
- public void SutractFromEnemyRLList()
- {
- _enemyRLGameObjectCountList.Remove(_enemyRLPrefab);
- }
- public void SutractFromEnemyLRList()
- {
- _enemyLRGameObjectCountList.Remove(_enemyLRPrefab);
- }
- IEnumerator StartSecondWaveRtoL()
- {
- _isRLCoroutineStarted = true;
- _uiManager.StartWaveTwoText();
- yield return new WaitForSeconds(6f);
- _canSpawnSecondPowerUpWave = true;
- StartCoroutine(SpawnPowerUpRoutineSecondWave()); //************starting the powerUpWave2 Coroutine***********//
- while (_stopSpawningOnPlayerDeath == false && _stopSpawningRLEnemy == false)
- {
- Vector3 randomXPos = new Vector3(12f, Random.Range(-0.52f, 4.80f), 0);
- GameObject newEnemyRL = Instantiate(_enemyRLPrefab, randomXPos, Quaternion.identity);
- newEnemyRL.transform.parent = _enemyContainer.transform;
- if (_enemyRLGameObjectCountList.Count <= 3)
- {
- _stopSpawningRLEnemy = true;
- }
- yield return new WaitForSeconds(_wave2WaitTime);
- }
- }
- IEnumerator StartSecondWaveLtoRight()
- {
- _isLRCoroutineStarted = true;
- yield return new WaitForSeconds(6f);
- while (_stopSpawningOnPlayerDeath == false && _stopSpawningLREnemy == false)
- {
- Vector3 randomXpos = new Vector3(-12f, Random.Range(-0.52f, 4.80f), 0);
- GameObject newEnemyLR = Instantiate(_enemyLRPrefab, randomXpos, Quaternion.identity);
- newEnemyLR.transform.parent = _enemyContainer.transform;
- if (_enemyLRGameObjectCountList.Count <= 3)
- {
- _stopSpawningLREnemy = true;
- }
- yield return new WaitForSeconds(_wave2WaitTime2);
- }
- }
- IEnumerator SpawnPowerUpRoutineSecondWave()
- {
- yield return new WaitForSeconds(3.0f);
- while (_stopSpawningOnPlayerDeath == false && _canSpawnSecondPowerUpWave == true)
- {
- Vector3 spawnPosRando = new Vector3(Random.Range(-9.21f, 9.21f), 12f, 0);
- int randompowerUpSpawn = Random.Range(0, 8);
- Instantiate(_powerUps[randompowerUpSpawn], spawnPosRando, Quaternion.identity);
- yield return new WaitForSeconds(Random.Range(3f, 10f));
- }
- }
- IEnumerator SpawnBoss()
- {
- _isBossSpawn = true;
- _uiManager.StartNecrSpacerText();
- yield return new WaitForSeconds(5f);
- GameObject boss = Instantiate(_bossFight, new Vector3(0.17f, 4.41f, 0), Quaternion.identity);
- Instantiate(_laserAmmo, transform.position, Quaternion.identity);
- Instantiate(_laserAmmo, transform.position, Quaternion.identity);
- }
- public void OnPlayerDeath()
- {
- _stopSpawningOnPlayerDeath = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement