Search Unity

Accessing the Active property in Toggle via c# script

Discussion in 'UGUI & TextMesh Pro' started by pKallv, Aug 27, 2014.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    I have problems with Toggle Groups, which is reported as a bug (http://forum.unity3d.com/threads/how-to-create-a-toggle-group.264229/) that Unity is looking at.

    However, I am trying to attach a script to my two toggles to make sure that only one of the toggles can be active at one time. My problem is how to i access the Active property on the Toggles via script. Anyone that can share some light on this as I cannot find this in the maul, or i look at the wrong place.
     
  2. vrm2p

    vrm2p

    Joined:
    Jul 23, 2014
    Posts:
    17
    use the property isOn:

    GameObject.Find("toggleX").GetComponent<Toggle>().isOn = true;


    Edit: ToggleGroups work fine for me:
    1. Create your toggles
    2. Add the Component ToggleGroup to one of the Toggles
    3. Choose this ToggleGroup as "Group" Property in the Inspector of each Toggle
     
  3. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    I have problem with Toggle Group, see link above, so for the time being I have to do it via script.

    Your help worked so thanks :)
     
  4. thearch

    thearch

    Joined:
    May 3, 2014
    Posts:
    13
    Hi, please check this tut it might help you.