Hey, I’m writing a simple android game and I have this problem because I want to make that if one Toggle is selected, the other one turns off. I did it this way, as you can see below, but I get the error “The requested operation caused a stack overflow”. Each click on the Toggle causes the game to jam for 1 - 2 seconds, and after some 4 clicks, the game crashes. Please, because I don’t know how to solve it
using System.Collections;
using System.Collections.Generic;
using System.Runtime;
using UnityEngine;
using UnityEngine.UI;
public class Menu : MonoBehaviour
{
public GameObject playObj;
public GameObject optionsObj;
public GameObject exitObj;
public GameObject owneObj;
public Slider volume;
public Toggle roadLeft;
public Toggle roadRight;
public void PlayButton()
{
playObj.SetActive(true);
}
public void OptionsButton()
{
optionsObj.SetActive(true);
}
public void OwneButton()
{
owneObj.SetActive(!owneObj.activeInHierarchy);
}
public void SumbitButton()
{
optionsObj.SetActive(!optionsObj.activeInHierarchy);
}
public void ExitButton()
{
exitObj.SetActive(true);
}
public void InfoButton()
{
Application.OpenURL("...");
}
//Options
void Start()
{
volume.value = AudioListener.volume;
volume.onValueChanged.AddListener(delegate { OnVolumeValueChange(); });
roadRight.GetComponent<Toggle>();
roadLeft.GetComponent<Toggle>();
}
public void OnVolumeValueChange()
{
AudioListener.volume = volume.value;
}
public void OnDirectionValueChangeLeft()
{
roadLeft.isOn = false;
roadLeft.isOn = true;
}
public void OnDirectionValueChangeRight()
{
roadRight.isOn = false;
roadRight.isOn = true;
}
}