unity滑条控制音量事件

Niaoyu
  • unity
  • unity
小于 1 分钟

slider.onValueChanged.AddListener

slider.onValueChanged.AddListener((float v) =>
        {//v等价于slider.value
            AudioTuning.Instance.SetMasterVolume(v);
        });

AudioTuning:

public class AudioTuning : SingLeton<AudioTuning>
{
    [SerializeField] AudioMixer audioMixer;
    public void SetMasterVolume(float volume)
    {
        audioMixer.SetFloat("MasterVolume", volume);
    }
}
Loading...