public void startRace(string pathToMap) { ReadMapFromFile rSystem = new ReadMapFromFile(pathToMap); Map m = new Map(rSystem.map, rSystem.allStarts, rSystem.finish); serverCallDrawMap(rSystem.map); //blueCar CarFactory blueCar = new BlueCar(m); //greenCar CarFactory greenCar = new GreenCar(m); //redCar CarFactory redCar = new RedCar(m); //Добавление всех автомобилей в списки List <CarFactory> cars = new List <CarFactory>(); cars.Add(blueCar); cars.Add(greenCar); cars.Add(redCar); createCars(cars); Thread[] _carThread = new Thread[3]; //Пока все автомобиле не достигнут финиша while (!blueCar.finished && !greenCar.finished && !redCar.finished) { //Создаем список текущих позиций всех машин List <CarState> allCS = new List <CarState>(); foreach (CarFactory car in cars) { allCS.Add(car.cState); } foreach (CarFactory car in cars) { //Инициализируем в классе каждой машины поле со списком текущих позиций всех машин. car.allCS = allCS; int i = 0; _carThread[i] = new Thread(new ParameterizedThreadStart(car.goForOneStep)); _carThread[i].Start(m); i++; } foreach (CarFactory car in cars) { drawCar(car, m.map); } Thread.Sleep(500); } }
private void Start() { SetNextResponsibility(FindObjectOfType <CarSpawner>()); redCar = Instantiate(redCar); redCar.gameObject.SetActive(false); blueCar = Instantiate(blueCar); blueCar.gameObject.SetActive(false); greenCar = Instantiate(greenCar); greenCar.gameObject.SetActive(false); }