Hello I’m linking together separate buttons to mute and unmute audio.
Here’s the mute script: Updated
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 550, 65, 35), "Mute")) {
audio.mute = true;
var script1 = GetComponent("UnMuteButton");
script1.enabled = true;
var script2 = GetComponent("MuteButton");
script2.enabled = false;
PlayerPrefs.SetInt("AudioIsMuted", 1);
}
}
And here’s the unmute script:
GetComponent("UnMuteButton").enabled = false;
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 550, 65, 35), "Unmute")) {
audio.mute = false;
var script1 = GetComponent("UnMuteButton");
script1.enabled = false;
var script2 = GetComponent("MuteButton");
script2.enabled = true;
}
}
When the Mute button is clicked the audio becomes muted and the button is replaced by an Unmute button, and vice versa. What I’d like to know is how can I use PlayerPrefs to save
whether or not the Player has muted or unmuted the audio and access their preferences whenever they return? I understand a little about PlayerPrefs but not a whole lot.
Thank you for any answers or feedback,
-Ben
Update I’ve updated the mute code, adding PlayerPrefs.SetInt("AudioIsMuted", 1);
I’m using
function Update(){
var audioIsMuted = PlayerPrefs.GetInt("AudioIsMuted") ==1;
}
To load the player’s preference but I still can’t get it to work.