Create Radio Buttons Behavior Using Toggle Component


RadioButtonSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
 
public class RadioButtonSystem : MonoBehaviour
{
    ToggleGroup toggleGroup;
 
    void Start()
    {
        toggleGroup = GetComponent<ToggleGroup>();
    }
 
    public void Submit()
    {
        Toggle toggle = toggleGroup.ActiveToggles().FirstOrDefault();
        Debug.Log(toggle.name + " _ " + toggle.GetComponentInChildren<Text>().text);
    }
}