I want to add some music in my game that can play in every scene, and if scenes change music doesn't start again and can be turn off on setting menu
can someone help me to figure it out?
What have you tried so far? Show your code. There is a way to achieve what you want, that is by using DontDestroyOnLoad
function. Create a gameObject, add AudioSource
to it and then add the below script to that gameObject:
public class AudioPlayerManager: MonoBehaviour
{
private static AudioPlayerManager instance = null;
private AudioSource audio;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
return;
}
if (instance == this) return;
Destroy(gameObject);
}
void Start()
{
audio = GetComponent<AudioSource>();
audio.Play();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With