0
\$\begingroup\$
OnGUI()
{
            for (int i = 0; i < scenes; i++)
            {
                GUILayout.Toggle(false, SceneManager.GetSceneAt(i).name);
            }

            if (GUILayout.Toggle(true, "New Scene"))
            {
                Debug.Log("True now !");
            }
}

First in the loop I'm adding some toggles. Then I want to do that if specific toggle is checked(true) do something and if unchecked(false) do something else.

But the way I did it it's just changing the toggle to true automatic.

\$\endgroup\$
2
  • \$\begingroup\$ Do please stop using OnGui and start using the new UI. \$\endgroup\$ Aug 15, 2018 at 22:40
  • \$\begingroup\$ This question seems to be related to an editor utility. If so, then that’s not really an option. \$\endgroup\$
    – Ed Marty
    Aug 16, 2018 at 12:02

1 Answer 1

0
\$\begingroup\$

The idiom with most of these GUI controls is to store a member variable representing the current state / value held inside the control. When you draw the control, you pass that variable so that it's drawn in the correct state. The function then returns the new value of the variable based on user input.

bool isToggleChecked;

void OnGUI() {
    isToggleChecked = GUILayout.Toggle(isToggleChecked, "Toggle Name");

    if(isToggleChecked) {
        // What to do if the toggle is in the checked state
    } else {
        // What to do if the toggle is in the unchecked state
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .