Hello I’m linking together separate buttons to mute and unmute audio. When the Mute button is clicked the audio becomes muted and the button is replaced by an Unmute button, and vice versa.
Here’s the mute script:
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 555, 65, 35), "Mute")) {
audio.mute = true;
var script1 = GetComponent("UnMuteButton");
script1.enabled = true;
var script2 = GetComponent("MuteButton");
script2.enabled = false;
PlayerPrefs.SetInt("AudioIsMuted", 1);
}
}
I’ve tried the line ‘PlayerPrefs.SetInt(“AudioIsMuted”, 1);’ to set the players preference.
And here’s the unmute script:
GetComponent("UnMuteButton").enabled = false;
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 555, 65, 35), "Unmute")) {
audio.mute = false;
var script1 = GetComponent("UnMuteButton");
script1.enabled = false;
var script2 = GetComponent("MuteButton");
script2.enabled = true;
PlayerPrefs.SetInt("AudioIsMuted", 2);
}
}
This time using ‘PlayerPrefs.SetInt(“AudioIsMuted”, 2);’ to set the other preference.
And finally this is the script I’m trying to use to retrieve the PlayerPrefs, I’ve name it CheckMutePreferences:
var audioIsMuted: int;
function Update(){
audioIsMuted = PlayerPrefs.GetInt("AudioIsMuted");
}
The problem is that it’s simply not working. In the inspector the audioIsMuted var corresponds with whether or not the audio is muted, or unmuted. But when I, for example, click on mute and the unmute button appears and then I change scenes and return I find that it’s no longer muted, and the unmute button isn’t displayed. I’m not sure where I’m going wrong.
Thank you for any answers or feedback, -Ben