internal void Update() { volume.Update(Time.deltaTime); // If this channel is no longer audible, destroy it. if (volume.CurrentValue == 0) { Destroy(gameObject); } // If this channel has no more voices, destroy it. else if (DestroyWhenNoVoicesExist && transform.childCount == 0) { Destroy(gameObject); } }
private void Update() { // Update audio parameters var channel = GetComponentInParent <Channel>(); Source.volume = volume.Update(Time.deltaTime) * channel.Volume; Source.pitch = pitch.Update(Time.deltaTime); Source.panStereo = panStereo.Update(Time.deltaTime); Source.spatialBlend = spatialBlend.Update(Time.deltaTime); // Wait until there is no silence remaining before playing the audio if (remainingLeftSilence > 0) { remainingLeftSilence -= Time.deltaTime; if (remainingLeftSilence < 0) { remainingLeftSilence = 0; Source.Play(); } } // Wait until there is no silence remaining after playing the audio if (remainingLeftSilence == 0 && !Source.isPlaying && remainingRightSilence > 0) { remainingRightSilence -= Time.deltaTime; if (remainingRightSilence < 0) { remainingRightSilence = 0; } } // If we can no longer hear this voice and there is no more silence // to generate, destroy it. var audible = Source.isPlaying && Source.volume != 0; if (remainingLeftSilence <= 0 && remainingRightSilence <= 0 && !audible) { Destroy(gameObject); } }