Good evening all.
I have a problem with my android game made with unity right now. I searched a lot in the interwebz and it seems that this is a common problem but never gets answered.
I have a global AudioController (dont destroy on load) that turns on/off the sound (using AudioListener.enabled) whenever I tick the UI Toggle in my options menu.
In editor play mode everything works like I want it to. but when I build the game and play it on my android, the audio is always on. no matter if I check the Toggle and the checkmark disappears, it seems that the audio listener is still enabled.
what could be the problem here?
AudioController.cs:
using UnityEngine;
public class audioController : MonoBehaviour {
private static audioController audController;
public AudioListener audioListener;
public AudioSource audioSource;
public AudioClip passedSFX;
public AudioClip failedSFX;
void Awake () {
DontDestroyOnLoad(this);
if (audController == null)
{
audController = this;
}
else
{
DestroyObject(gameObject);
}
}
void Update () {
}
public void TurnSoundOn()
{
audioListener.enabled = true;
}
public void TurnSoundOff()
{
audioListener.enabled = false;
}
public void PlayPassedSFX()
{
audioSource.clip = passedSFX;
audioSource.Play();
}
public void PlayFailedSFX()
{
audioSource.clip = failedSFX;
audioSource.Play();
}
}
OptionsMenuController.cs:
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class optionsMenuController : MonoBehaviour {
public GameObject audioManager;
public Toggle sfxToggle;
void Awake () {
audioManager = GameObject.Find("AudioManager");
if (audioManager.GetComponent<AudioListener>().enabled == true)
{
sfxToggle.isOn = true;
}
else
{
sfxToggle.isOn = false;
}
}
void Update () {
}
public void OpenMainMenu()
{
SceneManager.LoadScene(0);
}
public void OpenHighscoresMenu()
{
SceneManager.LoadScene("HighscoreMenu");
}
public void ToggleSFX()
{
if (sfxToggle.isOn == true)
{
audioManager.GetComponent<audioController>().TurnSoundOn(); }
else
{
audioManager.GetComponent<audioController>().TurnSoundOff();
}
}
}
thank you for your patience.