- Home /
Question by
dennisfomichevf65 · Mar 12, 2019 at 11:41 PM ·
savesave datasettingsoptions
How to save options menu?
Hello there. I was wondering how to make a button like apply to my options menu, because when you go select the settings, and you go to the pause menu, and go back to the menu and select it, all the settings are gone.
Comment
Answer by tablazonsimon · Mar 13, 2019 at 03:22 AM
You could use PlayerPrefs for this.
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
For example, if you have a mute button in your Options menu, make it so that when the button is clicked, it sets something like:
PlayerPrefs.SetInt("audioIsMuted",1);
And if it's turned off, it would be:
PlayerPrefs.SetInt("audioIsMuted",0);
And then, so that these options stay, you would need to check them at the start. So:
void Start(){
if(PlayerPrefs.GetInt("audioIsMuted") == 1)
{
muteAudio();
} else { dontMuteAudio(); }
}
And for volumes, you'd use float. For example:
private float audioVolume;
void Start() {
audioVolume = PlayerPrefs.GetFloat("volume");
}
void Update() {
volumeSlider.value = audioVolume;
audioVolume = PlayerPrefs.SetFloat("volume");
}