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; public int number = 0; public Vector2 createTime; [Header("40为标准速度")] public Vector2 speed; 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(createTime.x, createTime.y)); number++; GameObject car = Instantiate(carPrefabs[Random.Range(0, carPrefabs.Length)],transform); car.GetComponent().OpenMove(birth[Random.Range(0, birth.Count)],Random.Range(speed.x,speed.y)); } } } }