1. Unity 5.6 is now released.
    Dismiss Notice
  2. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  3. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice

Radio buttons

Discussion in 'Extensions & OnGUI' started by ITAmember, Jun 4, 2010.

  1. ITAmember

    ITAmember

    Joined:
    Feb 13, 2010
    Posts:
    88
    I would like to make a radio button control out of multiple toggle controls. However, since each of the toggle controls are independent of each other you can select multiple ones, I only want the user to be able to select one at a time.

    I know I can do this with brute force in scripting by storing the last state of the toggle, testing for change, and setting all the others to false, but there should be a better way.

    If my description of a radio button is confusing here is a wikipedia link. http://en.wikipedia.org/wiki/Radio_button
     
  2. unitymatrix

    unitymatrix

    Joined:
    Dec 29, 2009
    Posts:
    100
    oferei likes this.
  3. ITAmember

    ITAmember

    Joined:
    Feb 13, 2010
    Posts:
    88
    Thank you, works great!
     
  4. mythicwave

    mythicwave

    Joined:
    Jul 13, 2008
    Posts:
    144
     
  5. mythicwave

    mythicwave

    Joined:
    Jul 13, 2008
    Posts:
    144
    Actually, I got it without SelectionGrid. The code isn't that tricky :roll:
     
  6. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    301
    I can't believe i fiddled farted with this for hours, when "unitymatrix" had the perfect solution!

    Thanks!

    -Raiden
     
  7. Cesarecf

    Cesarecf

    Joined:
    Sep 1, 2012
    Posts:
    3
  8. vikingfabian-com

    vikingfabian-com

    Joined:
    Dec 5, 2013
    Posts:
    9
    oferei and rainabba like this.
  9. rainabba

    rainabba

    Joined:
    Dec 10, 2014
    Posts:
    3
    Looks great, but the selection won't change and I can't find ANY decent documentation on EditorStyles.radioButton. Do I need to add a handler or something?
     
  10. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    183
    EditorStyles is just a regular GUIStyle but it's themed with the editor art, it does not effect input at all. My guess is that you copied and pasted the code above without looking at how it works.

    If you notice the first argument is a 0 and GUILayout.SelectionGrid returns an int. Try saving that value and sending it back in.

    http://docs.unity3d.com/ScriptReference/GUILayout.SelectionGrid.html
     
  11. balthatrix

    balthatrix

    Joined:
    Mar 23, 2015
    Posts:
    3