SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Spawner : MonoBehaviour {
- public static Spawner Instance;
- [SerializeField] private GameObject[] _enemyPool;
- [SerializeField] private GameObject _bomb;
- [SerializeField] private GameObject[] _bompSpawnPlace;
- [SerializeField] private GameObject[] _warningObj;
- [SerializeField] private GameObject _bodyBuilder;
- [SerializeField] private GameObject _rocket;
- public float TimeForEnemySpawn;
- public bool BossLive;
- [SerializeField] private int _countBoss;
- [SerializeField] private float _scoreBoss;
- [SerializeField] private GameObject[] _boss;
- [SerializeField] private GameObject[] _players;
- private void Awake()
- {
- if (!Instance)
- {
- Instance = this;
- }
- else
- {
- DestroyImmediate(this.gameObject);
- }
- }
- private void Start()
- {
- StartCoroutine(SpawnEnemyPool());
- StartCoroutine(SpawnBomb());
- StartCoroutine(SpawnBodyBuilder());
- StartCoroutine(SpawnRockect());
- StartCoroutine(SpawnBoss());
- Instantiate(_players[ValueManager.Instance.IndexPlayer], new Vector3(0, 0, 0), Quaternion.identity);
- }
- IEnumerator SpawnEnemyPool()
- {
- if (!BossLive)
- {
- var rund = Random.Range(-4f, 4f);
- Instantiate(_enemyPool[Random.Range(0, _enemyPool.Length)], new Vector2(transform.position.x, rund), Quaternion.identity);
- }
- yield return new WaitForSeconds(0.5f);
- StartCoroutine(SpawnEnemyPool());
- yield return null;
- }
- private IEnumerator SpawnBomb()
- {
- yield return new WaitForSeconds(15f);
- if (!BossLive)
- {
- for (int i = 0; i < 3; i++)
- {
- _warningObj[i].SetActive(true);
- }
- yield return new WaitForSeconds(1f);
- for (int q = 0; q < _bompSpawnPlace.Length; q++)
- {
- Instantiate(_bomb, _bompSpawnPlace[q].transform.position, Quaternion.Euler(0, 0, 90));
- }
- yield return new WaitForSeconds(1f);
- for (int i = 0; i < 3; i++)
- {
- _warningObj[i].SetActive(false);
- }
- yield break;
- }
- yield return new WaitForSeconds(25f);
- StartCoroutine(SpawnBomb());
- yield return null;
- }
- IEnumerator SpawnBodyBuilder()
- {
- yield return new WaitForSeconds(7.5f);
- if (!BossLive)
- {
- float new_y = -3f;
- for (int i = 0; i < 3; i++)
- {
- Instantiate(_bodyBuilder, new Vector3(11, new_y, 0), Quaternion.identity);
- new_y += 3;
- }
- }
- yield return new WaitForSeconds(20f);
- StartCoroutine(SpawnBodyBuilder());
- yield return null;
- }
- private IEnumerator SpawnRockect()
- {
- yield return new WaitForSeconds(20f);
- if (!BossLive)
- {
- for (int i = 3; i < _warningObj.Length; i++)
- {
- _warningObj[i].SetActive(true);
- yield return new WaitForSeconds(1f);
- }
- yield return new WaitForSeconds(1f);
- for (int i = 3; i < _warningObj.Length; i++)
- {
- Vector3 dir = _warningObj[i].transform.position - CharacterController.Instance.transform.position;
- dir.Normalize();
- float rot = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
- 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));
- yield return new WaitForSeconds(0.5f);
- }
- for (int i = 3; i < _warningObj.Length; i++)
- {
- _warningObj[i].SetActive(false);
- yield return new WaitForSeconds(0.3f);
- }
- yield return new WaitForSeconds(20f);
- StartCoroutine(SpawnRockect());
- yield return null;
- }
- }
- private IEnumerator SpawnBoss()
- {
- int count = 1;
- yield return new WaitForSeconds(10f);
- if (GameManager.Instance.Score >= _scoreBoss)
- {
- Instantiate(_boss[_countBoss], new Vector3(), Quaternion.identity);
- Debug.Log(_scoreBoss * (_countBoss + 1));
- _scoreBoss += _scoreBoss * count;
- count++;
- _countBoss++;
- }
- StartCoroutine(SpawnBoss());
- yield return null;
- }
- }
RAW Paste Data

