public static IEnumerator fadeOut(this GvrAudioSoundfield audioSource, float duration) { float startVolume = audioSource.volume; float counter = 0f; while (counter < duration) { audioSource.volume = Mathf.Lerp(startVolume, 0, counter / duration); counter += Time.deltaTime; yield return(new WaitForEndOfFrame()); } audioSource.volume = 0; audioSource.Stop(); }
private IEnumerator FadeOutAmbiAudio(GvrAudioSoundfield audioSoundField, float closeTimeSpreader) { float minMask = 0.0f; float maxMask = gvrTargetVolume; float currMask = audioSoundField.volume; while (currMask > minMask && cancelBlink == false) { audioSoundField.volume = Mathf.Lerp(minMask, maxMask, currMask); currMask -= closeTimeSpreader * Time.deltaTime; yield return(null); } audioSoundField.volume = minMask; audioSoundField.Stop(); }