Master Audio source volume control with slider

Hi all, I am a new game developer. I want to setup an audio source in my starting scene which will be the master volume controller , it will control the sound volume of all the audio source in various scenes of my game. I’ve made the slider its working on the ‘start’ screen but after moving to other scenes the volume goes back to the set value in the respective scenes (I’ve multiple audio sources attached to the main camera of each scene). It looks like I’ve to use a script to handle this. I’ve made a C# script which takes one main ‘AudioSource’ and set each audiosource in all the scenes to the main audiosource. Script goes something like this -

using UnityEngine;
using System.Collections;

public class ChangeVolumeAll : MonoBehaviour
{

    AudioSource[] asc;
    //private static float vol = GameObject.GetComponents<AudioSource>().volume;
    public AudioSource MasterAudioSource;
    // Use this for initialization
    void Start()
    {
        asc = GetComponents<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        SetVolume();
    }

    public void SetVolume()
    {
        for (int i = 0; i < asc.Length; i++)
        {
            asc*.volume = MasterAudioSource.volume;*

}
}
I think this is working fine but the problem is that when some other scene is loaded from the start scene the volume is getting changed to the original set value. Probably this is due to overwriting of volume details after the scene is getting loaded. How can I achieve the result ?

@shantanusingh994 If you want to set anything up for the player to save you need to use PlayerPrefs or PlayerPrefsManager. I have a “musicManager” which starts at the splash screen to initialize the music. I also have a “levelManager” which calls the level/scene to go to. One other thing, I am using the UI Slider element for my volume control, this is common in mobile development but check out Unity’s documentation if you end up using something else to control your volume (i.e. a text field with a number between 1 and 100). I believe this should help as I use it in one of my games but look at the following code setting up an options screen.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class OptionsController : MonoBehaviour {

	public Slider volumeSlider;
	public Slider difficultySlider;
	public LevelManager levelManager;

	private MusicManager musicManager;
	// Use this for initialization
	void Start () {
		musicManager = GameObject.FindObjectOfType<MusicManager> ();

		volumeSlider.value = PlayerPrefsManager.GetMasterVolume ();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void SaveAndExit () {
		PlayerPrefsManager.SetMasterVolume (volumeSlider.value);
		levelManager.LoadLevel ("Start Menu");
	}
}

If this doesn’t work let me know or post your errors and I will attempt to help the best I can.