Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Resetting Toggles

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

  1. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,865
    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.
     
    rahulkuks likes this.
  3. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,865
    I appreciate that... but I posted this 3 years ago.
     
unityunity