Adjusting volume of an audio source from a previous scene
I have a problem with adjusting volume with a slider.
In the first scene, the scene where the audiosource is located, the volume slider works just fine. But because I want the audiosource to continue playing between scenes, I've assigned a script with a simple DontDestroyOnLoad(this); on it. The problem is when I try to make a volume slider of the next scene change the volume of the audiosource that was located in the previous scene, because I can't seem to assign something from one scene to another in the Unity manager. My game is pretty simple so far, so adjusting things isn't a big deal. Help would be great!
Answer by arvindiitkgp · Feb 20, 2016 at 04:21 PM
you can assign the AudioSource by simply tagging the audio source object (the object in the previous scene) and then use GameObject.FindWithTag("tag") and use GetComponent...
Example:
AudioSource source;
void Start () {
source = GameObject.FindWithTag("tag").GetComponent<AudioSource>();
}
Hope this will help :)
Unity Docs Reference : Tags