PlayerPrefs Help

Hi there!

I need some help with a script I’m working on. I have a settings menu and there’s a button that I can press that turns the background music on or off. I need to save some information by using PlayerPrefs.

I know how to save ints, floats, strings etc. But one problem I have is to save booleans.

When I press the “Sound Off” button this piece of code activates “songObject.audio.volume = 0.0;”. The songObject is the object that has the sound file on it.

I’ve implemented so when you press the button it stays highlighted, thats why I have “soundOn” and “soundOnSelected”.

So in some way I need to save if the sound is On or Off. I’ve tested using the “PlayerPrefsX” script from the Unity wiki but it didn’t work unfortunately.

//On
if (soundOn)
{
	if (GUI.Button (Rect (Screen.width/2-250, Screen.height - 250, 130, 40), "ON", "button"))
	{
		soundOn = false;
		soundOff = true;
		soundOnSelected = true;
		soundOffSelected = false;
		songObject.audio.volume = 1.0;
		AudioSource.PlayClipAtPoint(clickSound, transform.position);
	}
}
if (soundOnSelected)
{
	if (GUI.Button (Rect (Screen.width/2-250, Screen.height - 250, 130, 40), "ON", "buttonSelected2"))
	{
		soundOnSelected = true;
		soundOffSelected = false;
		songObject.audio.volume = 1.0;
		AudioSource.PlayClipAtPoint(clickSound, transform.position);
	}
}
//Off
if (soundOff)
{
	if (GUI.Button (Rect (Screen.width/2-50, Screen.height - 250, 130, 40), "OFF", "button"))
	{
		soundOn = true;
		soundOff = false;
		soundOnSelected = false;
		soundOffSelected = true;
		songObject.audio.volume = 0.0;
		AudioSource.PlayClipAtPoint(clickSound, transform.position);
	}
}
if (soundOffSelected)
{
	if (GUI.Button (Rect (Screen.width/2-50, Screen.height - 250, 130, 40), "OFF", "buttonSelected2"))
	{
		soundOnSelected = false;
		soundOffSelected = true;
		songObject.audio.volume = 0.0;
		AudioSource.PlayClipAtPoint(clickSound, transform.position);
	}
}

There is no boolean for player prefs. Create an appropriately name int player pref if you want it to be true(if it does not already exist), destroy this player pref if you want it to be false(if it exists). Then just check for weather it exists in whatever part of the game this matters in.