Question by
dekovicc · Jul 27, 2020 at 10:14 AM ·
playerprefstoggletoggle buttonoptionsswitch-case
Toggable music and saving of music state
Hello,
I'm working on an options menu but i kinda struck a wall. I have 2 toggles, one for music and one for sfx. I want to make so the game remembers users input and I'm using switch (MusicInt)
switch for changing int, but it wont switch between cases. Also i cant get the game remember game state and switch. Thank you in advance! :)
Switch Code:
public static void Music()
{
int MusicInt = 1;
switch (MusicInt)
{
case 1:
MusicInt = 1;
PlayerPrefs.SetInt("MusicM", MusicInt);
break;
case 2:
MusicInt = 0;
PlayerPrefs.SetInt("MusicM", MusicInt);
break;
}
Debug.Log(MusicInt);
}
Comment
Answer by dekovicc · Jul 27, 2020 at 10:33 AM
Get toggles' isOn bool, and then you can change it simply, i couldn't managed to remember game to save toggle state :( Here is my code maybe it helps someone.
public AudioMixer mixer;
public void Music(bool isOn)
{
if (isOn)
{
mixer.SetFloat("Music", -80f);
}
else if (!isOn)
{
mixer.SetFloat("Music", 0f);
}
}
public void SFX(bool isOn)
{
if (isOn)
mixer.SetFloat("SFX", -80f);
else if (!isOn)
mixer.SetFloat("SFX", 0f);
}
}