linked GUILayout.Toggle

hi folks!

is there an easy way to link two toggle buttons, f.e. for choosing one language option out of two possible languages?

thnx!

Read the manual about GUI styles.

I think you want the tool bar as it lets you have any number of language options and only one can be active at any one time. You can also have it in a column instead of a row if you prefer.

/* GUI.Toolbar example */

var toolbarInt = 0;
var toolbarStrings : String[] = ["Toolbar1", "Toolbar2", "Toolbar3"];

function OnGUI () {
    toolbarInt = GUI.Toolbar (Rect (25, 25, 250, 30), toolbarInt, toolbarStrings);
}

This seems to work for just two options:

bool choice1 = true;
bool choice2 = false;

void OnGUI(){
   choice1 = GUILayout.Toggle(!choice2, new GUIContent("Choice 1"));
   choice2 = GUILayout.Toggle(!choice1,new GUIContent("Choice 2"));
}

I have used a more general purpose solution multiple options I called a toggle group. The controller paints the group of buttons and the index of the true toggle gets painted with a true in the GUILayout call. If a button is pressed (other than the current true toggle) the controller's selected index gets reset to the new index.

for (var i=0;i<4;i++){

    	toogleBool _= GUI.Toggle(Rect(locX + (200 * (i + 1)),locY + (disY * 3),200,40),toogleBool*,"Choice " + (i+1));*_

* }*

for (i=0;i<4;i++){
* if(activeToogle != i)*
* {*
_ if(toogleBool == true)
* {
toogleBool[activeToogle] = false;
toogleBool = true;
activeToogle = i;
}
}
} *_

var toogleBool = new Array(true,false,false,false);

var activeToogle = 0;

function OnGUI()

{

    for (var i=0;i<4;i++){

    	toogleBool _= GUI.Toggle(Rect((200 * (i + 1)),100,toogleBool*,"Choice " + (i+1));*_

* }*

for (i=0;i<4;i++){
* if(activeToogle != i)*
* {*
_ if(toogleBool == true)
* {
toogleBool[activeToogle] = false;
toogleBool = true;
activeToogle = i;
}
}
} *_

}