/// <summary> /// This will spawn 2 vehicles at each end of this transline. /// Will reuse deactivated vehicles if exist or it will create a new vehicle. /// </summary> protected void SpawnAndResetTimer() { if (timeController == null) { return; } startTime = timeController.gameTime; GameObject vehicle; if (vehiclesOutOfService.Count > 0) { vehicle = vehiclesOutOfService.First(); vehiclesOutOfService.Remove(vehicle); vehicle.SetActive(true); vehicle.GetComponent <VehicleController>().ResetVehicle(LineDirection.OutBound); } else { vehicle = VehicleController.CreateGameObject(transline, LineDirection.OutBound); vehicle.transform.SetParent(transform); transline.AddVehicle(vehicle); } if (vehiclesOutOfService.Count > 0) { vehicle = vehiclesOutOfService.First(); vehiclesOutOfService.Remove(vehicle); vehicle.SetActive(true); vehicle.GetComponent <VehicleController>().ResetVehicle(LineDirection.InBound); } else { vehicle = VehicleController.CreateGameObject(transline, LineDirection.InBound); vehicle.transform.SetParent(transform); transline.AddVehicle(vehicle); } }