First of all you need to use is the pattern below to control all the scene's sounds in one place:
-Create a MusicManager class. It would better be singleton.
-Initialize an object from this class, and use DontDestroyOnLoad() in order to keep musicmanager alive when scene changes;
-Declare a static methods like:
public static void PlaySound(AudioClip clip);
public static void SetVolume(float volume);
- public static void Mute(){audioSourceObject.volume = 0f;}
-Then when it comes to play any audio, use these methods for playing sound by giving the sounds as a parameter.
-Also when it comes to mute just call the mute function.
For saving purposes:
PlayerPrefs.SetFloat("soundVolume", currentVolume); //Note that you need to keep the volume in a variable called currentVolume or whatever you name it.
And also when the game starts, put the code below in MusicManager class' void start()
method:
currentVolume = PlayerPrefs.GetFloat("soundVolume");
SetVolume(currentVolume); //This function has been defined above
By doing these, if the player mutes the game, the musicmanager will set the volume to 0f, then save it as 0f when the game gets closed. And also be re-set as 0f when the game is opened again.
Hope this helps!