I have a game with a settings menu. In this menu I have a toggle button that should turn music on or off when you enter the actual game (wich is another scene).
The code of the button is this:
public void MusicOnOff()
{
int muzicaonoff = PlayerPrefs.GetInt(“muzica”, 0);
if (muzicaonoff == 0) {
PlayerPrefs.SetInt (“muzica”, 1);
MuzicaText.text = “Music is On”;
}
else {
PlayerPrefs.SetInt (“muzica”, 0);
MuzicaText.text = “Music is Off”;
}
}
And the code from the actual game (the other scene) is this:
void Start()
{
//some things
int muzicaonoff = PlayerPrefs.GetInt(“muzica”, 0);
if (muzicaonoff == 0)
muzica.gameObject.SetActive (false);
else
muzica.gameObject.SetActive (true);
//some other things
}
When you click the toggle music button it should change the value “muzica” to 1 if it was 0 and to 0 if it was not 1. But when I enter the game (the other scene), it sets the music on if the value of “muzica” was 0, and sets the music off if the value of “muzica” was 1 (exactly the opposite). The frustrating thing is that i have a button in the other scene wich resets the current scene. And when you press it the value of 0 and 1 changes again…
I don’t get it, why this happens?