Search Unity

Question Custom Graph Radio Buttons

Discussion in 'UGUI & TextMesh Pro' started by David42142, Sep 19, 2020.

  1. David42142

    David42142

    Joined:
    Jul 15, 2015
    Posts:
    13
    Hello I hope im in the proper forum,

    im creating a custom node system. When adding a node I use this code to add two checkboxes to the node:

    Code (CSharp):
    1. Node tempDialogueNode
    2. var button = new Toggle("1");
    3. var button2 = new Toggle("2");
    4. tempDialogueNode.extensionContainer.Add(button);
    5. tempDialogueNode.extensionContainer.Add(button2);
    However i would like these boxes to work like radio buttons, so only one can be checked at a time.
    Is there a system in place like the toggle group for ui?
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Is your
    Toggle
    in the namespace
    UnityEngine.UI
    ?

    If yes, you are in the right forum.

    But you cannot create Toggles with a constructor. You should have compile errors. You rather create prefabs, instantiate them and get the Toggle component out of them.
    To make it radio buttons you need to have one "Toggle Group" component and assign that to all toggles.

    If no, you are in the wrong forum.