ui radio button

hi guys, Im trying to create a UI with a radio option button in it

in the unity UI I saw i can create a toggle, so i did.

  1. its not exsectly shaped as radio option button.

  2. I can choose 2 options, and thats somthing i cant have, how can I change it only to one

thanks in advance


Hi ! To answer your first question, when you create a toogle you see that it has “background” as a child, click it. Now you’ll see in the inspector that it has a Source Image below the Image (Script) componente. Press on the right side the circle to the right of the Source Image slot. Change your background image to whichever fits the shape you considered it is a radio option buttón.

Regarding your second question you have to add the toggle to a group. What does this mean. Create several toggles for instance and later select and drag (you have to do it simultaneously) one of the toggles different from the one you are seeing in the inspector from the Hierarchy View Panel and drag it to the Group property of the Toggle (Script) component . At the beginning you’ll see the slot of this property saying None (Toggle Group). But once you drag and drop another Toggle it will appear the group that that toggle belongs to.

I think this is exactly what you are looking for:

 int selected =0;
public void OnGUI()
string[] options = new string[] { "  version 1", "  version 2" };
selected = GUILayout.SelectionGrid(selected, options, 1, EditorStyles.radioButton);
if (selected == 0)
                    Debug.Log("version 1 is selected");
else if (selected == 1)
                    Debug.Log("version 2 is selected");