public void PlayOne(AudioSourceInterface audioInterface) { if (fadeInsteadOfStopping) { if (members.Contains(audioInterface)) { foreach (AudioSourceInterface asi in members) { if (audioInterface.gameObject.activeInHierarchy && asi != audioInterface) //hey, don't fade down the one thing we WANT to play. { asi.StartCoroutine(asi.FadeVolumeByFactor(fadeFactor, fadeDuration)); //fade out //fade back in after the length of time of the - hopefully - clip that is playing. asi.StartCoroutine(asi.FadeVolumeByFactor(1, fadeDuration, audioInterface.audioSource.clip.length)); } } audioInterface.ForcePlay();//play this clip at the appropriate time. } } else { if (members.Contains(audioInterface)) { StopAll(); audioInterface.ForcePlay(); } else { Debug.LogWarning("audio source not member of group.", audioInterface); } } }
void OnCollisionEnter(Collision col) { float newVolume = Mathf.Clamp01(col.relativeVelocity.magnitude * collisionVolume); audioInterface.SetVolume(newVolume); audioInterface.SetClip(sourceClips[Random.Range(0, sourceClips.Length - 1)]); if (ignoreGroupForCollisions) { audioInterface.ForcePlay(); } else { audioInterface.Play(); } }