public void Update() { if (active && list != null && list.Size() > 0) { timeToSoundPulse += Time.deltaTime; if (currentlyPlayingSound != null && timePlayingSound >= currentlyPlayingSound.length) { // Debug.Log("Ending sound"); source.Stop(); currentlyPlayingSound = null; } if (currentlyPlayingSound != null && timePlayingSound < currentlyPlayingSound.length) { // Debug.Log("Sound is playing"); timePlayingSound += Time.deltaTime; MeshRenderer renderer = this.gameObject.GetComponent <MeshRenderer>(); if (renderer != null) { // Debug.Log("Updating color"); float fourth = currentlyPlayingSound.length / 4; float threeFourths = 3 * currentlyPlayingSound.length / 4; float lightMultiplier = 1; Color thisColor = CubeColor; if (timePlayingSound <= fourth) { float percentage = timePlayingSound / fourth; lightMultiplier += maxLightMultiplier * percentage; thisColor = Color.Lerp(CubeColor, CubeSpeakingColor, percentage); } else if (timePlayingSound > fourth && timePlayingSound <= threeFourths) { lightMultiplier += maxLightMultiplier; thisColor = CubeSpeakingColor; } else { float percentage = 1 - ((timePlayingSound - threeFourths) / fourth); lightMultiplier += maxLightMultiplier * percentage; thisColor = Color.Lerp(CubeColor, CubeSpeakingColor, percentage); } Material material = renderer.material; renderer.material.SetColor("_EmissionColor", thisColor); // Debug.Log("Color was: "+thisColor); Light light = this.gameObject.GetComponentInChildren <Light>(); //light.color = thisColor; light.intensity = baseLightValue * lightMultiplier; light.range = baseLightRange * lightMultiplier; } } if (timeToSoundPulse >= nextPulseTime) { // Debug.Log(this.name+" triggering pulse"); TriggerSoundPulse(); timeToSoundPulse = 0; nextPulseTime = Random.Range(MinTimeBetweenAudio, MaxTimeBetweenAudio); } } }