Hey i have a little problem and i hope someone can help me.
I want to make a list of GUI.Toggle and when you have a toggle on and then click on another one the active one should turn off.
I tried something and it kind of worked:
toggletest=GUI.Toggle(Rect(200,200,50,50),toggletest,"tes1");
toggletest2=GUI.Toggle(Rect(270,200,50,50),toggletest2,"tes2");
if(toggletest)
toggletest2=false;
if(toggletest2)
toggletest=false;
It only works when you have the second one selected and then click on the first one.
If you know how to fix the code above or if you know another, better way to do it I would be happy to read it. Help is much appreciated.
My way to do it :
if(GUI.Toggle(Rect(200,200,50,50),toggletest,"tes1")) {
toggletest = true;
toggletest2 = false;
}
if(GUI.Toggle(Rect(270,200,50,50),toggletest2,"tes2")) {
toggletest = false;
toggletest2 = true;
}
I found it out myself:
//in OnGUI(){
if(GUI.Toggle(Rect(200,200,50,50),toggletest,"tes1")) toggletest=setMeOnly();
if(GUI.Toggle(Rect(270,200,50,50),toggletest2,"tes2")) toggletest2=setMeOnly();
...}
function setMeOnly():boolean{
toggletest = toggletest2 = false;
return true;
}
Still if someone knows an even better way then just post it as an answer.
HI everybody,
I’m facing the same problem. The thing is I have tried each of your solutions, and searched for it, but I can’t manage to have it working in C# oO
Any help greatly appreciated !
This is how i think my code would look like in C. I did this for jeanclaude2010
Hope this works because like i said i’m not used to work with C
public bool toogletest1 = false;
public bool toogletest2 = false;
void OnGUI(){
if(GUI.Toggle(new Rect(200,200,50,50),toggletest,"tes1")) toggletest=setMeOnly();
if(GUI.Toggle(new Rect(270,200,50,50),toggletest2,"tes2")) toggletest2=setMeOnly();
}
void setMeOnly():bool{ //not entirely sure if bool works maybe its boolean
toggletest = toggletest2 = false;
return true;
}
Works perfectly, I had forgotten to use public variables.
Many thanks !