how to change and save audio volume from a different scene with a slider

im trying to make an options menu for a game that has a slider for changing the master volume for the whole game. i have a audio source on the main menu that plays the music over all the scenes but do not know how to access that audio source to change and then save that volume when changing between the other menu screens. any help would be much appreciated.

Hello. Your options should be persistant saved.

So, when a player sets the volume with the slider and hits Apply (or Save button whatever you name it), you should store this value to playerprefs. Try this to save this value :

PlayerPrefs.SetFloat("Options_VolumeLevel", SliderObject.GetComponent<Slider>().value);

This single code of line will save the slider’s value to your prefs location (Register for Windows, android->data for android etc).

Not, when you change your scene, on your initialize method, before started playing your music, retrieve this value to change your AudioSource volume like this :

AudioSourceObject.GetComponent<AudioSource>().volume = PlayerPrefs.GetFloat("Options_VolumeLevel", 1f);

This second value is the default value if the key does not exist.

Do the same when the user opens the options panel to change slider value to corresponding value.
Hope that helped.