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 ?