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.
37 lines
1.1 KiB
37 lines
1.1 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;
|
|
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<Car>().OpenMove(birth[Random.Range(0, birth.Count)],10*Random.Range(4,8));
|
|
}
|
|
}
|
|
}
|
|
}
|