- Home /
How Do I Turn Off Toggle in a ToggleGroup ?
I have three ToggleGroups. Each ToggleGroup provides one variable for a Custom Class. I select one item from group one, one from group two, one from group three, and press "Select" and an instance is added to the Custom Class. Everything works fine...no problems with anything so far.
Here's where the problem comes in. After a selection is made, I want to reset all the toggles in each ToggleGroup to "Off/Null/False" so that another selection can be made. I'm struggling greatly on how to accomplish this. The following works perfectly to select the class variable:
if (togAlpha01.isOn) {classVariableNum = 1;}
if (togAlpha02.isOn) {classVariableNum = 2;}
if (togAlpha03.isOn) {classVariableNum = 3;}
...But After I choose my variables, and when I press the "Select" button, I want to reset all the Toggles to "Off/Empty/Null/Blank" so that a new group of Toggles can be selected. Any ideas on how to reset these Toggles? I've searched online and tried about everything that comes up with IntelliSense but I haven't got it to work yet. Thanks in advance for any suggestions.
Answer by Hellium · Apr 17, 2018 at 02:55 PM
if( toggleGroup1.AnyTogglesOn() )
toggleGroup1.SetAllTogglesOff();
if( toggleGroup2.AnyTogglesOn() )
toggleGroup2.SetAllTogglesOff();
if( toggleGroup3.AnyTogglesOn() )
toggleGroup3.SetAllTogglesOff();
https://docs.unity3d.com/ScriptReference/UI.ToggleGroup.SetAllTogglesOff.html
Thanks. I tried some variations of "toggle.isOn = false" but they didn't work. Although I did not try specifically what you have presented. I will try your suggestion immediately and see if it works. Thank you for taking the time to assist me.
Exactly, this should work, except if the ToggleGroup has allowSwitchOff
set to false
. Then the last isOn = false;
might not take effect.
Your answer
Follow this Question
Related Questions
Access UI.Toggle from c# CodeBehind -How does one set the Toggle created in the front end of Unity? 1 Answer
Multiple Cars not working 1 Answer
Do Something ONLY when all Toggles are On or Off 4 Answers
Distribute terrain in zones 3 Answers
Is there a method to create toggle group behavior for standard buttons 1 Answer