I can’t figure out whats wrong here so I could really use some assistance. I have a toggle switch that mutes and unmutes the game. Its setting is pulled through player prefs and when the switch setting is off it causes a stack overflow when loading the menu. It does not cause a stack overflow if the switch setting is on.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MuteManager : MonoBehaviour
{
private bool isMuted;
public Toggle soundToggle;
private bool isToggled;
// Start is called before the first frame update
void Start()
{
isMuted = PlayerPrefs.GetInt("MUTED") == 1;
isToggled = PlayerPrefs.GetInt("TOGGLED") == 1;
AudioListener.pause = isMuted;
soundToggle.isOn = isToggled;
}
public void MutePressed()
{
isMuted = !isMuted;
isToggled = !isToggled;
AudioListener.pause = isMuted;
soundToggle.isOn = isToggled;
PlayerPrefs.SetInt("MUTED", isMuted ? 1 : 0);
PlayerPrefs.SetInt("TOGGLED", isToggled ? 1 : 0);
}
}