How do i turn on/off background music and keep the changes when reload the scene
Hi everyone! I have a Canvas with two buttons (music on/music off) and i want to change and keep the change when reload the same scene. But how I do it ?
Here is my code.
public GameObject BtnOn;
public GameObject BtnOff;
public AudioSource BackGroundMusic;
public void SoundBtnOn()
{
if (BtnOn == true)
{
BackGroundMusic.Pause();
ClickBtn.Play();
BtnOn.SetActive(false);
BtnOff.SetActive(true);
Debug.Log("sound btnon");
}
}
public void SoundBtnOff()
{
if (BtnOff == true)
{
BackGroundMusic.Play();
ClickBtn.Play();
BtnOn.SetActive(true);
BtnOff.SetActive(false);
Debug.Log("sound btnof");
}
}
I tried use DontDestroyOnLoad but It doesn't work. want just that for me to finish my first game. I would appreciate any help.
Comment
Best Answer
Answer by tanoshimi · May 07, 2016 at 07:00 AM
DontDestroyOnLoad does work, and that's exactly what it's for - to maintain the state of objects between scenes.
I suggest you check out some tutorials which show how to use it, such as: