using System; using UnityEngine; using UnityEngine.UI; namespace Script.UI { public class AnsweringToggleHelper : MonoBehaviour { public int index; private Toggle _toggle; private Action action; public Toggle toggle => _toggle; private void Awake() { _toggle = GetComponent(); _toggle.onValueChanged.AddListener(OnValueChanged); } private void OnDestroy() { _toggle.onValueChanged.RemoveListener(OnValueChanged); } private void OnValueChanged(bool arg0) { if (arg0) action?.Invoke(index); } public void SetAction(Action ac) { this.action = ac; } } }