public IEnumerator EaseToChangeVolume(AudioAsset au, string name, bool isLoop, float volumeScale, float delay, float fadeTime) { AudioClip ac = GetAudioClip(name); float oldVolume = au.Volume; float target = au.Volume; if (au.audioSource && au.IsPlay) { while (target > 0f) { float speed = oldVolume / fadeTime; target = target - speed * Time.fixedDeltaTime; au.Volume = target; yield return(new WaitForFixedUpdate()); } au.Stop(); } au.assetName = name; au.audioSource.clip = ac; au.audioSource.loop = isLoop; au.Play(delay); target = 0; yield return(new WaitForSeconds(delay)); while (target < oldVolume) { float speed = oldVolume / fadeTime * 1.2f; target = target + speed * Time.fixedDeltaTime; au.Volume = target; yield return(new WaitForFixedUpdate()); } au.VolumeScale = volumeScale; }