using System.Collections; using System.Collections.Generic; using UnityEngine; public class WaveManager : MonoBehaviour { [Header("Wave 1 (civil cars)")] public GameObject civilCar; public float CivilCarSpawnDelay; public int CivilCarsAmout; [Header("Wave 2 (PoliceBomb cars)")] public GameObject PoliceBombCar; public int bombsAmount; public int policecarVerticalSpeed; public int policecarHorizontalSpeed; public float bombDelay; private GameObject spawnedPoliceBombCar; private bool isSpawned; private bool is2ndSpawned; [Header("Wave 3 (PoliceB cars)")] public GameObject PoliceCarB; public int PoliceCarBAmount; [HideInInspector] static public bool isLeft; [HideInInspector] static public bool isRight; public float shootingSeriesDelay; public float singleShotDelay; public float policeCarBVerticalSpeed; public int bulletsInSeries; private GameObject spawnedPoliceCarB; [Header("Points")] public int pointsPerCivilCar; public int pointsPerPoliceBombCar; public int pointsPerBomb; public int pointsPerPoliceBCar; public GameObject EndGameScreen; private float[] lanesArray; private float spawnDelay; void Start() { lanesArray = new float[4]; lanesArray[0] = -2.13f; lanesArray[1] = -0.76f; lanesArray[2] = 0.76f; lanesArray[3] = 2.13f; spawnDelay = CivilCarSpawnDelay; } void Update() { spawnDelay -= Time.deltaTime; if (spawnDelay <= 0 && CivilCarsAmout > 0) { SpawnCar(); spawnDelay = CivilCarSpawnDelay; } else if (CivilCarsAmout <= 0 && is2ndSpawned == false) { if(isSpawned == false) { spawnPoliceBombCar(); } else if(isSpawned == true && spawnedPoliceBombCar.GetComponent().bombsAmount < 10 && is2ndSpawned == false) { spawnPoliceBombCar(); } } else if (CivilCarsAmout <= 0 && PoliceCarBAmount > 0 && spawnedPoliceBombCar == null) { spawnPoliceCarB(); } else if(PoliceCarBAmount <= 0 && isLeft == false && isRight == false) { //Time.timeScale = 0; EndGameScreen.SetActive(true); } } void spawnPoliceCarB() { Transform playerCarPosition; if(GameObject.FindWithTag("Player")) { playerCarPosition = GameObject.FindWithTag("Player").transform; }else if(GameObject.FindWithTag("Shield")) { playerCarPosition = GameObject.FindWithTag("Shield").transform; }else if(GameObject.FindWithTag("Untouchable")) { playerCarPosition = GameObject.FindWithTag("Untouchable").transform; } else { playerCarPosition = null; } if(playerCarPosition.position.x <= -0.2f && isRight == false) { spawnedPoliceCarB = (GameObject)Instantiate(PoliceCarB, new Vector3(2.25f, -6f, 0), Quaternion.identity); spawnedPoliceCarB.GetComponent().isLeft = false; isRight = true; PoliceCarBAmount--; } else if(playerCarPosition.position.x > -0.2f && isLeft == false) { spawnedPoliceCarB = (GameObject)Instantiate(PoliceCarB, new Vector3(-2.25f, -6f, 0), Quaternion.identity); spawnedPoliceCarB.GetComponent().isLeft = true; isLeft = true; PoliceCarBAmount--; } spawnedPoliceCarB.GetComponent().shootingSeriesDelay = shootingSeriesDelay; spawnedPoliceCarB.GetComponent().singleShotDelay = singleShotDelay; spawnedPoliceCarB.GetComponent().policeCarBVerticalSpeed = policeCarBVerticalSpeed; spawnedPoliceCarB.GetComponent().bulletsInSeries = bulletsInSeries; spawnedPoliceCarB.GetComponent().pointsPerCar = pointsPerPoliceBCar; } void spawnPoliceBombCar() { if (isSpawned == false) { spawnedPoliceBombCar = (GameObject)Instantiate(PoliceBombCar, new Vector3(Random.Range(-2.3f, 2.3f), 7f, 0), Quaternion.identity); spawnedPoliceBombCar.GetComponent().bombDelay = bombDelay; isSpawned = true; } else if (isSpawned == true && is2ndSpawned == false) { if (spawnedPoliceBombCar.transform.position.x < 0.5f) { spawnedPoliceBombCar = (GameObject)Instantiate(PoliceBombCar, new Vector3(2.2f, 7f, 0), Quaternion.identity); is2ndSpawned = true; } else if (spawnedPoliceBombCar.transform.position.x >= 0.5f) { spawnedPoliceBombCar = (GameObject)Instantiate(PoliceBombCar, new Vector3(-2.2f, 7f, 0), Quaternion.identity); is2ndSpawned = true; } spawnedPoliceBombCar.GetComponent().bombDelay = bombDelay / 1.5f; } spawnedPoliceBombCar.GetComponent().bombsAmount = bombsAmount; spawnedPoliceBombCar.GetComponent().policecarVerticalSpeed = policecarVerticalSpeed; spawnedPoliceBombCar.GetComponent().policecarHorizontalSpeed = policecarHorizontalSpeed; spawnedPoliceBombCar.GetComponent().pointsPerCar = pointsPerPoliceBombCar; spawnedPoliceBombCar.GetComponent().bomb.GetComponent().pointsPerBomb = pointsPerBomb; } void SpawnCar() { int lane = Random.Range(0, 4); if (lane == 0 || lane == 1) { GameObject car = (GameObject)Instantiate(civilCar, new Vector3(lanesArray[lane], 6f, 0), Quaternion.Euler(new Vector3(0, 0, 180))); car.GetComponent().direction = 1; car.GetComponent().civilCarSpeed = 9f; car.GetComponent().pointsPerCar = pointsPerCivilCar; } if (lane == 2 || lane == 3) { GameObject car = (GameObject)Instantiate(civilCar, new Vector3(lanesArray[lane], 6f, 0), Quaternion.identity); car.GetComponent().pointsPerCar = pointsPerCivilCar; } CivilCarsAmout--; } }