/// <summary> /// Spaws the police car. /// </summary> /// <returns><c>true</c>, if police car was spawed, <c>false</c> otherwise.</returns> public bool SpawPoliceCar() { // test if all the road is empty foreach (Road r in roads) { if (TestForward(r) != null) { return(false); } } if (policeCarPrefab == null) { return(false); } GameObject carObj = Instantiate(policeCarPrefab); CarPolice carCom = carObj.GetComponent <CarPolice>(); if (carCom == null) { Destroy(carObj); return(false); } Car chaseCar = TrafficManager.Instance.carList[Random.Range(0, TrafficManager.Instance.carList.Count)]; chaseCar.AffectedByPolice = false; carCom.SetTargetCar(this, chaseCar); TrafficManager.RegisterCar(carCom); return(true); }
public void SpawCar() { // if the car numbers hit the max, // do not create more cars if (TrafficManager.IsCarMaximum()) { return; } // test if all the road is empty foreach (Road r in roads) { if (TestForward(r) != null) { return; } } if (carPrefabs.Length > 1) { for (int i = 0; i < 1; i++) { if ((i == 0) && (RedSwitch)) { GameObject carObj = Instantiate(carPrefabs[0]); Car carCom = carObj.GetComponent <Car>(); carCom.SetFromToLocation(this, targets[Random.Range(0, targets.Count)]); TrafficManager.RegisterCar(carCom); RedSwitch = false; } else { GameObject carObj = Instantiate(carPrefabs[1]); Car carCom = carObj.GetComponent <Car>(); carCom.SetFromToLocation(this, targets[Random.Range(0, targets.Count)]); TrafficManager.RegisterCar(carCom); } } } else { GameObject carObj = Instantiate(carPrefabs[Random.Range(0, carPrefabs.Length)]); Car carCom = carObj.GetComponent <Car>(); carCom.SetFromToLocation(this, targets[Random.Range(0, targets.Count)]); TrafficManager.RegisterCar(carCom); } }