Search Unity

Sound playerprefs between scenes !

Discussion in 'Scripting' started by Louis-LCM, Nov 22, 2014.

  1. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    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:

    Code (JavaScript):
    1. #pragma strict
    2. var muted = false;
    3. var CustomSkin: GUISkin;
    4. var musicMute : GUIStyle;
    5. var allSound : GUIStyle;
    6.  
    7.  
    8.   function Start (){
    9.   }
    10. function OnGUI(){
    11.      GUI.skin = CustomSkin;
    12.    
    13.      if(GUI.Button(new Rect(Screen.width * 0.20,Screen.height * 0.40, Screen.width * 0.20, Screen.height * 0.20), "Sound"))
    14.      {
    15.          if(muted == false){
    16.          AudioListener.volume = 0;
    17.          muted = true;
    18.          }
    19.          else{
    20.          AudioListener.volume = 1;
    21.          muted = false;
    22.          }
    23.      }
    24. }
     
  2. sootie8

    sootie8

    Joined:
    Mar 25, 2014
    Posts:
    233
    http://docs.unity3d.com/ScriptReference/PlayerPrefs.html

    For example in your script above would be
    Code (CSharp):
    1.  
    2. yourDesiredVolume = 1;
    3. PlayerPrefs.SetInt("Volume",  yourDesiredVolume);
    And in your sound manager in your next scene would be
    Code (CSharp):
    1. var volume = (PlayerPrefs.GetInt("Volume"));
    2. AudioListener.volume = volume;
     
    Louis-LCM likes this.
  3. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    I don't know why ... But it don't work ...
     
    Last edited: Nov 22, 2014
  4. sootie8

    sootie8

    Joined:
    Mar 25, 2014
    Posts:
    233
    Post your new code up
     
    Louis-LCM likes this.
  5. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    I solved :D ! I deleted the buttons and I replaced with sliders :D ! They are better !