You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace BuildSystem
|
|
{
|
|
public class CarController : MonoSingleton<CarController>
|
|
{
|
|
public List<Vector2Int> birth = new List<Vector2Int>();
|
|
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<Car>().OpenMove(birth[Random.Range(0, birth.Count)],Random.Range(speed.x,speed.y));
|
|
}
|
|
}
|
|
}
|
|
}
|