public class NewBehaviourScript : MonoBehaviour {
public AudioSource audioSource;
public Slider slider;
void Start () {
slider.onValueChanged.AddListener(SliderOnValueChanged);
float volume = 80;
if (PlayerPrefs.HasKey("audioVolume"))//判断是否保存audioVolume
{
volume = PlayerPrefs.GetFloat("audioVolume");//读取audioVolume
}
audioSource.volume = volume;
slider.value = volume;
}
void SliderOnValueChanged (float value) {
audioSource.volume = value;
PlayerPrefs.SetFloat("audioVolume",value);//保存audioVolume
}
}
调整音量并自动保存
最新推荐文章于 2024-08-20 16:13:34 发布