Hello, I’m trying to save my sound/music settings with Player Prefs after I either turn off the sound/music, or turn it on. So far I haven’t had any luck in doing so. I’ve used Player Prefs before to save my high score, but now I want to save my sound/music too. So how can I do this? Here’s my sound/music menu script to where you can either turn it on or off:
public class SoundAndMenu : MonoBehaviour {
public Texture backgroundTexture;
public float guiPlacementY1;
public float guiPlacementY2;
public float guiPlacementY3;
public float guiPlacementX1;
public float guiPlacementX2;
public float guiPlacementX3;
void OnGUI(){
// Display our background texture
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture);
// Display our Buttons
if (GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .5f, Screen.height * .1f), "On")) {
AudioListener.volume = 100;
AudioManager.AudioInstance.PlaySound ("Sound");
print(PlayerPrefs.GetInt("On"));
print ("Ckicked Play Game");
}
if (GUI.Button (new Rect (Screen.width * guiPlacementX3, Screen.height * guiPlacementY3, Screen.width * .5f, Screen.height * .1f), "Off")) {
AudioListener.volume = 0;
print(PlayerPrefs.GetInt("Off"));
print ("Clicked Play Game");
//Application.LoadLevel("SoundMenu");
}
if (GUI.Button (new Rect (Screen.width * guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .3f, Screen.height * .1f), "Back")) {
AudioManager.AudioInstance.PlaySound ("Back");
PlayerPrefs.Save();
print ("Clicked Play Game");
Application.LoadLevel ("OptionsMenu");
}
}
}
As you can tell, I already started messing around with the Player Prefs for this, but no luck. This was made early a while back so the usage of Player Prefs is wrong. Anyways thanks for reading.