Hi I have been researching a lot about this issue but i couldn't find the best solution of my problem.
So the problem is that my background music starts playing.I have got two buttons."On" and "Off". I want to mute the music so when i click my mute button,it from "On" goes to "Off" and the music stops.But when i change the scene and go back it returns to the button with the text "On" but the music is still stopped. So my question is only how to save the changed button without going back by default? Here is my script:
public GameObject on;
public GameObject off;
public string sound;
Soundtrack music;
static bool isMuted;
void Awake()
{
SoundCheck();
}
void Start()
{
music = FindObjectOfType<Soundtrack>();
}
public void Off()
{
if (isMuted == false)
{
on.gameObject.SetActive(false);
off.gameObject.SetActive(true);
music.s.Stop();
isMuted = true;
PlayerPrefs.SetString("Sound", "muted");
}
}
public void On()
{ if(isMuted==true)
{
on.gameObject.SetActive(true);
off.gameObject.SetActive(false);
music.s.Play();
isMuted = false;
PlayerPrefs.SetString("Sound", "enabled");
}
}
public void SoundCheck()
{
sound = PlayerPrefs.GetString("Sound");
if (sound == "enabled")
{
isMuted = false;
}
else if (sound == "muted")
{
isMuted = true;
}
}
}