Author Topic: Reset all checkboxes in a group  (Read 3305 times)

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Reset all checkboxes in a group
« on: July 13, 2014, 11:24:55 AM »
Hi,

Just started using NGUI and although the examples are very helpful there are a few things that arent covered. I' trying to make a multiple choice quiz game involving a round of questions with 4 possible answers to select from. I was wondering about a few things here;

1. How to detect whether any of the checkboxes in the group have been clicked. I'm using the following but not sure of its the best way;
  1. if (!UIToggle.GetActiveToggle(1))
  2. {
  3.    Debug.LogWarning(UIToggle.GetActiveToggle(1));
  4.    answerSelected = false;
  5. }
  6.  

2. How to reset the state of each checkbox to off or false after each round of questions. What I'm using right now is something like the following but what seems to happening is that the checkboxes selected previously remains true (and so cannot be clicked again);

  1. // Reset each of the Checkboxes
  2. foreach (GameObject go in ChoiceContainers)
  3. {
  4.    go.GetComponent<UIToggle>().startsActive = false;
  5.    go.GetComponent<UIToggle>().value = false;
  6. }
  7.      
  8. //Turn off the checkbox sprites
  9. foreach (GameObject obj in CheckboxSprites)
  10. {
  11.    obj.GetComponent<UISprite>().enabled = false;
  12. }
  13.  

3. How to set the starting state of the group to false to begin with. So they don't get set to false when starting the scene?

Any help with these would be great - Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reset all checkboxes in a group
« Reply #1 on: July 13, 2014, 05:49:05 PM »
1. UIToggle.GetActiveToggle(1) gives you the active toggle from the first group of toggles. If you know which group you're working with, that's a fine way of retrieving the active choice.

2. Don't try to set anything to 'false'. In a group of toggles, only one toggle can have a 'true' state, so setting one toggle to 'true' will automatically turn off others. If you want to turn off all of them, then setting their 'value' to false is enough, but you will want to also set the "optionCanBeNone" to 'true' first, otherwise it won't be possible to turn off the last option.

3. See #2.

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Re: Reset all checkboxes in a group
« Reply #2 on: August 05, 2014, 06:11:21 PM »
Perfect, optionCanBeNone was just what I needed!