BGJ-2022.1/Assets/Scripts/UI/OptionsMenu.cs

27 lines
748 B
C#

using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
namespace UI
{
public class OptionsMenu : MonoBehaviour
{
[SerializeField] private AudioMixer audioMixer = null;
[SerializeField] private Slider slider = null;
private const string MasterVolumeParameter = "MasterVolume";
private void Awake() => OnEnable();
private void OnEnable() => slider.value = PlayerPrefs.GetFloat(MasterVolumeParameter, 1f);
public void UpdateVolume() => SetVolume(slider.value);
public void SetVolume(float value)
{
audioMixer.SetFloat(MasterVolumeParameter, Mathf.Log10(value) * 20f);
PlayerPrefs.SetFloat(MasterVolumeParameter, value);
}
}
}