using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BuildSystem { public class CarController : MonoSingleton { public List birth = new List(); public GameObject[] carPrefabs; public int carNumber; int number = 0; void Start() { birth.Add(new Vector2Int(0 , 2)); birth.Add(new Vector2Int(10, 0)); birth.Add(new Vector2Int(3, 7)); birth.Add(new Vector2Int(13, 5)); StartCreateCar(); } public void StartCreateCar() { StartCoroutine(CreateCar()); } IEnumerator CreateCar() { while (true) { yield return new WaitUntil(() => { return number < carNumber; }); yield return new WaitForSeconds(Random.Range(2, 4)); number++; GameObject car = Instantiate(carPrefabs[Random.Range(0, carPrefabs.Length)],transform); car.GetComponent().OpenMove(birth[Random.Range(0, birth.Count)],10*Random.Range(4,8)); } } } }