using System.Collections; using System.Collections.Generic; using UnityEngine; #region Serializable classes [System.Serializable] public class EnemyWaves { [Tooltip("time for wave generation from the moment the game started")] public float timeToStart; [Tooltip("Enemy wave's prefab")] public GameObject wave; } #endregion public class LevelController : MonoBehaviour { //Serializable classes implements public EnemyWaves[] enemyWaves; public GameObject powerUp; public float timeForNewPowerup; public GameObject[] planets; public float timeBetweenPlanets; public float planetsSpeed; List planetsList = new List(); Camera mainCamera; private void Start() { mainCamera = Camera.main; //for each element in 'enemyWaves' array creating coroutine which generates the wave for (int i = 0; i().bounds.size.y / 2), Quaternion.identity ); } } IEnumerator PlanetsCreation() { //Create a new list copying the arrey for (int i = 0; i < planets.Length; i++) { planetsList.Add(planets[i]); } yield return new WaitForSeconds(10); while (true) { ////choose random object from the list, generate and delete it int randomIndex = Random.Range(0, planetsList.Count); GameObject newPlanet = Instantiate(planetsList[randomIndex]); planetsList.RemoveAt(randomIndex); //if the list decreased to zero, reinstall it if (planetsList.Count == 0) { for (int i = 0; i < planets.Length; i++) { planetsList.Add(planets[i]); } } newPlanet.GetComponent().speed = planetsSpeed; yield return new WaitForSeconds(timeBetweenPlanets); } } }