saving volume between scenes

I have a menu with a slider set up so I can adjust the volume. Although it works for my volume screen scene, it doesn’t work in any other scene. I think I need to store the hsliderValue but I’m not even sure TBH. would really appreciate an assist.

var backButton : Texture2D;
var backRollover : Texture2D;
var mouseEnterSound : AudioClip; 
var mouseExitSound : AudioClip; 
var hSliderValue : float = 0.5;
private var correctedMousePosition : Vector2;
private var mouseOver = false; // current mouse status
private var isOver = false; // used to check status change


function CheckButton(r: Rect, texOver: Texture2D, texOut: Texture2D): boolean {
    if ( r.Contains(correctedMousePosition) ) // if mouse over the button...
    {
    	GUI.DrawTexture( r, texOver ); // draw the over texture...
        isOver = true;  // set isOver flag...
    	return Input.GetMouseButtonUp(0); // and return mouse up status
    }
    else
    {
    	GUI.DrawTexture( r, texOut ); // otherwise draw regular texture...
     	return false; // and return false
    }
}

function OnGUI ()
{
    correctedMousePosition = Vector2 (Input.mousePosition.x, (Screen.height-Input.mousePosition.y) );
    isOver = false; // prepare mouse enter/exit detection
    
    hSliderValue = GUI.HorizontalSlider(Rect(300,180,200,20), hSliderValue, 0.0, 1.0);
    GUI.Label(Rect(300,195,200,20), "Music="+hSliderValue);
    audio.volume = hSliderValue;
    
    if ( CheckButton( Rect(250,250,200,50), backRollover, backButton) )
    {
        Application.LoadLevel(1);
    }
    if (isOver != mouseOver){ // if mouse entered or exited button...
        mouseOver = isOver;   // update mouseOver and play appropriate sound
        if (mouseOver){
            audio.PlayOneShot(mouseEnterSound);
        } else {
            audio.PlayOneShot(mouseExitSound);
        }  
    }
}

You need a script that stay alive through out game play say “PlayerSettings”

  1. Inside “PlayerSettings” call DontDestroyOnLoad(this) in Start() or Awake()
  2. add volume variable to store its value from slider and set its value.
  3. attach “PlayerSettings” to an empty gameobject

or you can use this :

PlayerPrefs.SetInt(“volume”, 10);
// this is an int

PlayerPrefs.SetFloat(“volume”, 10.0);
// this is a float

// and then just call it like this :

myScriptVolume =PlayerPrefs.GetInt(“volume”);
//to get the int

myScriptVolume =PlayerPrefs.GetFloat(“volume”);
// to get the float

// note this will save also the value if you close the unity game , and store it forever
untill you vant to erase it if you want and here is the code:

PlayerPrefs.DeleteKey(“volume”);

or just delete all

PlayerPrefs.DeleteAll();