AudioMixer.SetFloat メソッドは、指定した AudioGroup のボリュームを設定するためのものです。
第2引数に指定した値が、そのままボリューム値として設定されます。補間処理は適用されません。
audioMixerGroups[0].audioMixer.SetFloat(mixerGroupName, decibel);
補間処理を行いたい場合は、DOTween などのライブラリを使用することで実現できます。
以下は、DOTween を使用したサンプルコードです。
using DG.Tweening;
using UnityEngine;
using UnityEngine.Audio;
public class AudioMixerController : MonoBehaviour
{
[SerializeField] private AudioMixer audioMixer;
[SerializeField] private string mixerGroupName;
[SerializeField] private float duration;
public void SetLinearVolumeToMixerGroup(string mixerGroupName, float linerVolume) {
float decibel = 20.0f * Mathf.Log10(linerVolume);
if (float.IsNegativeInfinity(decibel)) {
decibel = -96f; // 無音は -80f ではなくて -96f にする
}
// DOTween を利用して補間処理を行う
audioMixerGroups[0].DOSetFloat(mixerGroupName, decibel, duration);
}
}
参考サイト
Github ハトネコエ 様
オーディオのフェードイン・フェードアウト:DOTween 使用(ブログ公開用)
https://gist.github.com/nekonenene/3643fe8e958fc8b...