I have a gameObject in my scene that has an Audio Source which plays the main themes music. When I choose to switch off the audio in the editor, it does so accordingly, then when I switch it back on, again, it behaves the way it’s supposed to.
The problem is, if I was to repeat this process on my android build, the music will constantly play, I can’t get it to stop. This couldn’t be any more frustrating so if anyone has any solutions for me, i’d greatly appreciate it.
#Edit#
#mainMenu.cs#
void Start()
{
if (PlayerPrefs.GetInt("audio", optionsMenu.audio) == 1)
{
Camera.main.GetComponent<AudioListener>().enabled = true;
}
else if (PlayerPrefs.GetInt("audio", optionsMenu.audio) == 0)
{
Camera.main.GetComponent<AudioListener>().enabled = false;
}
}
#optionsMenu.cs#
void checkAudio()
{
if (noAudio.isOn == true)
{
audio = 0;
PlayerPrefs.SetInt(“audio”, audio);
yesAudio.isOn = false;
}
else if (yesAudio.isOn == true)
{
audio = 1;
PlayerPrefs.SetInt("audio", audio);
noAudio.isOn = false;
}
else if (yesAudio.isOn == false && noAudio.isOn == false)
{
audio = 1;
PlayerPrefs.SetInt("audio", audio);
yesAudio.isOn = true;
}
}
This is the code I’m using, the options menu function is run in the update, I keep the players input in a player pref for later use, so then when the main menu is loaded, I have it checking to see what that value is.
Like I said, this all runs when I play it in Unity, just not on android