Sound playerprefs between scenes !

Hi everybody !

I have a mute script attached to a “Settings” scene. How I can make the volum save and work in another scene ?

Here is my script:

#pragma strict
var muted = false;
var CustomSkin: GUISkin;
var musicMute : GUIStyle;
var allSound : GUIStyle;
 
 
  function Start (){
  }
function OnGUI(){
     GUI.skin = CustomSkin;
    
     if(GUI.Button(new Rect(Screen.width * 0.20,Screen.height * 0.40, Screen.width * 0.20, Screen.height * 0.20), "Sound"))
     {
         if(muted == false){
         AudioListener.volume = 0;
         muted = true;
         }
         else{
         AudioListener.volume = 1;
         muted = false;
         }
     }
}

For example in your script above would be

yourDesiredVolume = 1;
PlayerPrefs.SetInt("Volume",  yourDesiredVolume);

And in your sound manager in your next scene would be

var volume = (PlayerPrefs.GetInt("Volume"));
AudioListener.volume = volume;
1 Like

I don’t know why … But it don’t work …

Post your new code up

1 Like

I solved :smile: ! I deleted the buttons and I replaced with sliders :smile: ! They are better !