how to make a song continue to play from the first scene to the last scene in unity code example
Example: music that stays when you change scene unity
using UnityEngine;
public class MusicClass : MonoBehaviour {
private AudioSource _audioSource;
private void Awake()
{
DontDestroyOnLoad(transform.gameObject);
_audioSource = GetComponent<AudioSource>();
}
public void PlayMusic()
{
if (_audioSource.isPlaying) return;
_audioSource.Play();
}
public void StopMusic()
{
_audioSource.Stop();
}
}