i have background music that plays throughout all of my scenes,
i have added “on” and “off” music buttons to a settings panel in my mainmenu scene
currently the “on” “off” music buttons work if i start the game in the mainmenu scene, however once i change scenes and go back to main menu,
my “on” “off” buttons no longer work
i will eventually be adding sound effects and will hope to be able to also turn off sound effects and music separately, but would like to get the background music working first
public class SoundManager : MonoBehaviour {
public AudioSource musicSource;
public static SoundManager instance = null;
void Awake ()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy (gameObject);
if (!musicSource.isPlaying)
{
DontDestroyOnLoad (gameObject);
}
}
public void PlayMusic()
{
musicSource.Play();
}
public void PauseMusic()
{
musicSource.Pause();
}
}