daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Spawner : MonoBehaviour {
  7.     public static Spawner Instance;
  8.     [SerializeField] private GameObject[] _enemyPool;
  9.     [SerializeField] private GameObject _bomb;
  10.     [SerializeField] private GameObject[] _bompSpawnPlace;
  11.     [SerializeField] private GameObject[] _warningObj;
  12.     [SerializeField] private GameObject _bodyBuilder;
  13.     [SerializeField] private GameObject _rocket;
  14.     public float TimeForEnemySpawn;
  15.     public bool BossLive;
  16.     [SerializeField] private int _countBoss;
  17.     [SerializeField] private float _scoreBoss;
  18.     [SerializeField] private GameObject[] _boss;
  19.     [SerializeField] private GameObject[] _players;
  20.     private void Awake()
  21.     {
  22.         if (!Instance)
  23.         {
  24.             Instance = this;
  25.         }
  26.         else
  27.         {
  28.             DestroyImmediate(this.gameObject);
  29.         }
  30.     }
  31.  
  32.     private void Start()
  33.     {
  34.         StartCoroutine(SpawnEnemyPool());
  35.         StartCoroutine(SpawnBomb());
  36.         StartCoroutine(SpawnBodyBuilder());
  37.         StartCoroutine(SpawnRockect());
  38.         StartCoroutine(SpawnBoss());
  39.         Instantiate(_players[ValueManager.Instance.IndexPlayer], new Vector3(0, 0, 0), Quaternion.identity);
  40.     }
  41.    
  42.     IEnumerator SpawnEnemyPool()
  43.     {
  44.         if (!BossLive)
  45.         {
  46.             var rund = Random.Range(-4f, 4f);
  47.             Instantiate(_enemyPool[Random.Range(0, _enemyPool.Length)], new Vector2(transform.position.x, rund), Quaternion.identity);
  48.         }
  49.         yield return new WaitForSeconds(0.5f);
  50.         StartCoroutine(SpawnEnemyPool());
  51.         yield return null;
  52.  
  53.     }
  54.    
  55.     private IEnumerator SpawnBomb()
  56.     {
  57.         yield return new WaitForSeconds(15f);
  58.         if (!BossLive)
  59.         {
  60.             for (int i = 0; i < 3; i++)
  61.             {
  62.                 _warningObj[i].SetActive(true);
  63.             }
  64.             yield return new WaitForSeconds(1f);
  65.             for (int q = 0; q < _bompSpawnPlace.Length; q++)
  66.             {
  67.                 Instantiate(_bomb, _bompSpawnPlace[q].transform.position, Quaternion.Euler(0, 0, 90));
  68.             }
  69.             yield return new WaitForSeconds(1f);
  70.             for (int i = 0; i < 3; i++)
  71.             {
  72.                 _warningObj[i].SetActive(false);
  73.             }
  74.             yield break;
  75.         }
  76.         yield return new WaitForSeconds(25f);
  77.         StartCoroutine(SpawnBomb());
  78.         yield return null;
  79.     }
  80.  
  81.     IEnumerator  SpawnBodyBuilder()
  82.     {
  83.         yield return new WaitForSeconds(7.5f);
  84.         if (!BossLive)
  85.         {
  86.             float new_y = -3f;
  87.             for (int i = 0; i < 3; i++)
  88.             {
  89.                 Instantiate(_bodyBuilder, new Vector3(11, new_y, 0), Quaternion.identity);
  90.                 new_y += 3;
  91.             }
  92.         }
  93.         yield return new WaitForSeconds(20f);
  94.         StartCoroutine(SpawnBodyBuilder());
  95.         yield return null;
  96.     }
  97.  
  98.     private IEnumerator SpawnRockect()
  99.     {
  100.         yield return new WaitForSeconds(20f);
  101.         if (!BossLive)
  102.         {
  103.             for (int i = 3; i < _warningObj.Length; i++)
  104.             {
  105.                 _warningObj[i].SetActive(true);
  106.                 yield return new WaitForSeconds(1f);
  107.             }
  108.             yield return new WaitForSeconds(1f);
  109.             for (int i = 3; i < _warningObj.Length; i++)
  110.             {
  111.                 Vector3 dir = _warningObj[i].transform.position - CharacterController.Instance.transform.position;
  112.                 dir.Normalize();
  113.                 float rot = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
  114.                 Instantiate(_rocket, new Vector3(_warningObj[i].transform.position.x, _warningObj[i].transform.position.y, _warningObj[i].transform.position.z - 25f), Quaternion.Euler(0, 0, rot));
  115.                 yield return new WaitForSeconds(0.5f);
  116.             }
  117.             for (int i = 3; i < _warningObj.Length; i++)
  118.             {
  119.                 _warningObj[i].SetActive(false);
  120.                 yield return new WaitForSeconds(0.3f);
  121.             }
  122.             yield return new WaitForSeconds(20f);
  123.             StartCoroutine(SpawnRockect());
  124.             yield return null;
  125.         }
  126.     }
  127.     private IEnumerator SpawnBoss()
  128.     {
  129.         int count = 1;
  130.         yield return new WaitForSeconds(10f);
  131.         if (GameManager.Instance.Score >= _scoreBoss)
  132.         {
  133.            
  134.             Instantiate(_boss[_countBoss], new Vector3(), Quaternion.identity);
  135.             Debug.Log(_scoreBoss * (_countBoss + 1));
  136.             _scoreBoss += _scoreBoss * count;
  137.             count++;
  138.             _countBoss++;
  139.         }
  140.         StartCoroutine(SpawnBoss());
  141.         yield return null;
  142.     }
  143.    
  144. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top