private void Awake() { carMovement = GetComponent <CarMovement>(); carsSound = CarsController.Instance.GetComponent <CarsSound>(); sensorVisualizer = sensor.GetComponentInChildren <SensorVisualizer>(); MeshRenderer[] carMeshRenderers = GetComponentsInChildren <MeshRenderer>(true); vehicleMeshRenderer = carMeshRenderers[0]; potatoVehicleMeshRenderer = carMeshRenderers[1]; genome = new Genome(inNodesNumber, outNodesNumber); }
private void SpawnCars() { // Create copies of materials because we don't want to change settings in the original materials: Material copyOfDefaultCarMaterial = new Material(carMaterial); Material copyOfCrashedCarMaterial = new Material(crashedCarMaterial); Material copyOfDefaultPotatoCarMaterial = new Material(potatoCarMaterial); Material copyOfCrashedPotatoCarMaterial = new Material(crashedPotatoCarMaterial); // Create cars and give them reference to materials: GameObject carsContainer = new GameObject("Cars"); population = new CarBrain[populationNumber]; GameObject[] cars = new GameObject[populationNumber]; for (int i = 0; i < populationNumber; i++) { GameObject car = Instantiate(carPrefab); car.name = "Car-" + i; car.transform.parent = carsContainer.transform; population[i] = car.GetComponent <CarBrain>(); cars[i] = car; MeshRenderer[] carMeshRenderers = car.GetComponentsInChildren <MeshRenderer>(true); carMeshRenderers[0].sharedMaterial = copyOfDefaultCarMaterial; carMeshRenderers[1].sharedMaterial = copyOfDefaultPotatoCarMaterial; population[i].CarMaterial = copyOfDefaultCarMaterial; population[i].CrashedCarMaterial = copyOfCrashedCarMaterial; population[i].PotatoCarMaterial = copyOfDefaultPotatoCarMaterial; population[i].CrashedPotatoCarMaterial = copyOfCrashedPotatoCarMaterial; } // Add cars array to object which will control the cars sound: CarsSound carsSound = GetComponent <CarsSound>(); carsSound.SetCarsMovements(cars); if (!Settings.IsAudioMuted) { carsSound.PlaySound(); } // Add cars array and change the cars graphics to low if 'Settings.IsPotatoGraphics' is true: Settings.SetAICars(cars); if (Settings.IsPotatoGraphics) { Settings.ChangeCarsGraphics(); } }
private IEnumerator EndSceneEffectBeforePopulationReset() { bloom.active = true; // Turn on bloom effect (when is set "potato" graphics then bloom is disabled, so enable it for a while). CarsSound carsSound = carsController.GetComponent <CarsSound>(); carsSound.StopSound(); for (int i = 4; i <= 60; i++) { bloom.intensity.value = i; yield return(new WaitForSecondsRealtime(0.02f)); } // Reset scene: Settings.SetPause(false); carsSound.StopSound(); // Stop again the engine sound because above method unmuted the audio. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); }