Advertisement
SizilStank

Untitled

Feb 27th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SpawnManager : MonoBehaviour
  6. {
  7.  
  8.     public GameObject _enemyPrefab;
  9.     [SerializeField] private GameObject _bigEnemyPrefab;
  10.     [SerializeField] private GameObject _enemyContainer;
  11.     [SerializeField] private GameObject _enemyRLPrefab;
  12.     [SerializeField] private GameObject _enemyLRPrefab;
  13.     [SerializeField] private GameObject _bossFight;
  14.     [SerializeField] private GameObject _laserAmmo;
  15.     [SerializeField] private GameObject _clearWave;
  16.  
  17.     public List<GameObject> _smallEnemyGameObjectCountList = new List<GameObject>();
  18.     public List<GameObject> _bigEnemyGameObjectCountList = new List<GameObject>();
  19.     public List<GameObject> _enemyRLGameObjectCountList = new List<GameObject>();
  20.     public List<GameObject> _enemyLRGameObjectCountList = new List<GameObject>();
  21.  
  22.     [SerializeField] private float _waitTime = 3f;
  23.     [SerializeField] private float _wave2WaitTime = 6f;
  24.     [SerializeField] private float _wave2WaitTime2 = 6f;
  25.     [SerializeField] private float _bigEnemyWaitTime = 6f;
  26.  
  27.     [SerializeField] private GameObject[] _powerUps;
  28.  
  29.     [SerializeField] private AudioClip _enemyExplod;
  30.  
  31.     [SerializeField] private bool _stopSpawningOnPlayerDeath;
  32.     [SerializeField] private bool _stopSpawningEnemy;
  33.     [SerializeField] private bool _stopSpawningBigEnemy;
  34.     [SerializeField] private bool _stopSpawningPowerUps;
  35.     [SerializeField] private bool _stopSpawningRLEnemy;
  36.     [SerializeField] private bool _stopSpawningLREnemy;
  37.     [SerializeField] private bool _canSpawnSecondPowerUpWave;
  38.  
  39.     [SerializeField] private bool _isRLCoroutineStarted;
  40.     [SerializeField] private bool _isLRCoroutineStarted;
  41.  
  42.     [SerializeField] private bool _isBossSpawn;
  43.  
  44.     UIManager _uiManager;
  45.     EnemyBossScript _enemyBossScript;
  46.  
  47.     private void Start()
  48.     {
  49.         _uiManager = GameObject.Find("Canvas").GetComponent<UIManager>();
  50.  
  51.         if (_enemyBossScript != null)
  52.         {
  53.             _enemyBossScript = GameObject.Find("MainBodyBoss").GetComponent<EnemyBossScript>();
  54.         }
  55.  
  56.         for (int i = 0; i < Random.Range(10, 30); i++)
  57.         {
  58.             _smallEnemyGameObjectCountList.Add(_enemyPrefab);
  59.         }
  60.  
  61.         for (int i = 0; i < Random.Range(5, 9); i++)
  62.         {
  63.             _bigEnemyGameObjectCountList.Add(_bigEnemyPrefab);
  64.         }
  65.  
  66.         for (int i = 0; i < Random.Range(10, 30); i++)
  67.         {
  68.             _enemyRLGameObjectCountList.Add(_enemyRLPrefab);
  69.         }
  70.  
  71.         for (int i = 0; i < Random.Range(10, 30); i++)
  72.         {
  73.             _enemyLRGameObjectCountList.Add(_enemyLRPrefab);
  74.         }
  75.  
  76.  
  77.  
  78.     }
  79.  
  80.     private void Update()
  81.     {
  82.        
  83.        
  84.  
  85.         if (_smallEnemyGameObjectCountList.Count <= 5 && _bigEnemyGameObjectCountList.Count <= 5 && _isLRCoroutineStarted == false && _isRLCoroutineStarted == false)
  86.         {
  87.             StartCoroutine(StartSecondWaveRtoL());
  88.             StartCoroutine(StartSecondWaveLtoRight());
  89.             _isRLCoroutineStarted = true;
  90.             _isLRCoroutineStarted = true;
  91.             _stopSpawningPowerUps = true;
  92.             //_canSpawnSecondPowerUpWave = true;// coroutine is already doing this when called....
  93.         }
  94.  
  95.         if (_enemyLRGameObjectCountList.Count <= 3 && _enemyRLGameObjectCountList.Count <= 3 && _isBossSpawn == false)
  96.         {
  97.             StartCoroutine(SpawnBoss());
  98.             _isBossSpawn = true;
  99.         }
  100.     }
  101.  
  102.     public void StartSpawn()
  103.     {
  104.         StartCoroutine(SpawnEnemyRoutine());
  105.         StartCoroutine(SpawnPowerUpRoutine());
  106.         StartCoroutine(SpawnBigEnemy());
  107.         _uiManager.StartWaveOneText();
  108.     }
  109.  
  110.  
  111.  
  112.     public void SubtractFromEnemyList()// being called from the enemyScript
  113.     {
  114.         _smallEnemyGameObjectCountList.Remove(_enemyPrefab);
  115.     }
  116.  
  117.     public void SubtractFromBigEnemyList()// being called from the BigEnemyScript
  118.     {
  119.         _bigEnemyGameObjectCountList.Remove(_bigEnemyPrefab);
  120.  
  121.     }
  122.  
  123.     IEnumerator SpawnEnemyRoutine()
  124.     {
  125.         yield return new WaitForSeconds(6.0f);
  126.         while (_stopSpawningOnPlayerDeath == false && _stopSpawningEnemy == false)
  127.         {
  128.                 Vector3 spawnPosRando = new Vector3(Random.Range(-9.21f, 9.21f), 9f, 0);
  129.                 GameObject newEnemy = Instantiate(_enemyPrefab, spawnPosRando, Quaternion.identity);
  130.                 newEnemy.transform.parent = _enemyContainer.transform;
  131.  
  132.                 yield return new WaitForSeconds(_waitTime);
  133.  
  134.             if (_smallEnemyGameObjectCountList.Count <=5)
  135.             {
  136.                 _stopSpawningEnemy = true;
  137.             }
  138.         }
  139.     }
  140.  
  141.     IEnumerator SpawnBigEnemy()
  142.     {
  143.         yield return new WaitForSeconds(10f);
  144.  
  145.         while (_stopSpawningOnPlayerDeath == false && _stopSpawningBigEnemy == false)
  146.         {
  147.                 Vector3 spawnPosRandom = new Vector3(Random.Range(9.21f, -9.21f), 9f, 0);
  148.                 GameObject newBigEnemy = Instantiate(_bigEnemyPrefab, spawnPosRandom, Quaternion.identity);
  149.                 newBigEnemy.transform.parent = _enemyContainer.transform;
  150.  
  151.                 yield return new WaitForSeconds(_bigEnemyWaitTime);
  152.  
  153.             if (_bigEnemyGameObjectCountList.Count <=5)
  154.             {
  155.                 _stopSpawningBigEnemy = true;
  156.             }
  157.         }
  158.     }
  159.  
  160.     IEnumerator SpawnPowerUpRoutine()
  161.     {
  162.         yield return new WaitForSeconds(6.0f);
  163.         while (_stopSpawningOnPlayerDeath == false && _stopSpawningPowerUps == false)
  164.         {
  165.                 Vector3 spawnPosRando = new Vector3(Random.Range(-9.21f, 9.21f), 9f, 0);
  166.                 int randompowerUpSpawn = Random.Range(0, 8);
  167.                 GameObject allThePowerUps = Instantiate(_powerUps[randompowerUpSpawn], spawnPosRando, Quaternion.identity);
  168.  
  169.                 yield return new WaitForSeconds(Random.Range(3f, 10f));
  170.         }
  171.     }
  172.  
  173.  
  174.     //*************Start Second Wave / PowerUps*************//
  175.  
  176.  
  177.     public void SutractFromEnemyRLList()
  178.     {
  179.         _enemyRLGameObjectCountList.Remove(_enemyRLPrefab);
  180.     }
  181.  
  182.     public void SutractFromEnemyLRList()
  183.     {
  184.         _enemyLRGameObjectCountList.Remove(_enemyLRPrefab);
  185.     }
  186.  
  187.     IEnumerator StartSecondWaveRtoL()
  188.     {
  189.         _isRLCoroutineStarted = true;
  190.         _uiManager.StartWaveTwoText();
  191.  
  192.         yield return new WaitForSeconds(6f);
  193.         _canSpawnSecondPowerUpWave = true;
  194.  
  195.         StartCoroutine(SpawnPowerUpRoutineSecondWave()); //************starting the powerUpWave2 Coroutine***********//
  196.  
  197.         while (_stopSpawningOnPlayerDeath == false && _stopSpawningRLEnemy == false)
  198.         {
  199.             Vector3 randomXPos = new Vector3(12f, Random.Range(-0.52f, 4.80f), 0);
  200.             GameObject newEnemyRL = Instantiate(_enemyRLPrefab, randomXPos, Quaternion.identity);
  201.             newEnemyRL.transform.parent = _enemyContainer.transform;
  202.  
  203.             if (_enemyRLGameObjectCountList.Count <= 3)
  204.             {
  205.                 _stopSpawningRLEnemy = true;
  206.             }
  207.  
  208.             yield return new WaitForSeconds(_wave2WaitTime);
  209.         }
  210.     }
  211.  
  212.     IEnumerator StartSecondWaveLtoRight()
  213.     {
  214.         _isLRCoroutineStarted = true;
  215.         yield return new WaitForSeconds(6f);
  216.  
  217.         while (_stopSpawningOnPlayerDeath == false && _stopSpawningLREnemy == false)
  218.         {
  219.             Vector3 randomXpos = new Vector3(-12f, Random.Range(-0.52f, 4.80f), 0);
  220.             GameObject newEnemyLR = Instantiate(_enemyLRPrefab, randomXpos, Quaternion.identity);
  221.             newEnemyLR.transform.parent = _enemyContainer.transform;
  222.  
  223.             if (_enemyLRGameObjectCountList.Count <= 3)
  224.             {
  225.                 _stopSpawningLREnemy = true;
  226.             }
  227.  
  228.             yield return new WaitForSeconds(_wave2WaitTime2);
  229.         }
  230.     }
  231.  
  232.     IEnumerator SpawnPowerUpRoutineSecondWave()
  233.     {
  234.         yield return new WaitForSeconds(3.0f);
  235.         while (_stopSpawningOnPlayerDeath == false && _canSpawnSecondPowerUpWave == true)
  236.         {
  237.                 Vector3 spawnPosRando = new Vector3(Random.Range(-9.21f, 9.21f), 12f, 0);
  238.                 int randompowerUpSpawn = Random.Range(0, 8);
  239.                 Instantiate(_powerUps[randompowerUpSpawn], spawnPosRando, Quaternion.identity);
  240.  
  241.                 yield return new WaitForSeconds(Random.Range(3f, 10f));
  242.         }
  243.     }
  244.  
  245.     IEnumerator SpawnBoss()
  246.     {
  247.         _isBossSpawn = true;
  248.  
  249.         _uiManager.StartNecrSpacerText();
  250.         yield return new WaitForSeconds(5f);
  251.  
  252.         GameObject boss = Instantiate(_bossFight, new Vector3(0.17f, 4.41f, 0), Quaternion.identity);
  253.         Instantiate(_laserAmmo, transform.position, Quaternion.identity);
  254.         Instantiate(_laserAmmo, transform.position, Quaternion.identity);
  255.     }
  256.  
  257.     public void OnPlayerDeath()
  258.     {
  259.             _stopSpawningOnPlayerDeath = true;
  260.     }
  261.  
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement