Search Unity

Resetting Toggles

Discussion in 'UGUI & TextMesh Pro' started by khanstruct, Apr 9, 2015.

  1. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    I have a group of Toggles in my game menu. I would like it to reset to have the first toggle selected whenever the menu opens.

    When I was doing this in my first "proof of concept", all I had to do was set toggle1 to isOn=true. However, in my new code, when I do that, it sets toggle1 to on, but it also leaves the last selected toggle on, and I can't figure out why.

    They are both members of the same toggle group, and "allow switch off" is false. The only difference is that, in my first code, toggle1 had the toggle group component. In this code, I have the toggle group set to the panel that contains them all.

    Is this meant to act this way? Am I doing something wrong? Am I missing something? Thanks!
     
  2. tkromeroa

    tkromeroa

    Joined:
    Apr 11, 2018
    Posts:
    1
    I did it this way:

    toggle.GetComponent<Toggle>().isOn = false;

    If the toggle is in a togglegroup, in the togglegroup component activate Allow to Swith Off option.
     
    diaosuyi and rahulkuks like this.
  3. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    I appreciate that... but I posted this 3 years ago.
     
  4. diaosuyi

    diaosuyi

    Joined:
    Jan 22, 2016
    Posts:
    2
    rofl