Hi I'm having a problem with creating two toggles where only one can be on, if one is pressed the other switches off.
i am using the following code
if (toggleVert == true){
toggleBrie = false;
}
if (toggleBrie == true){
toggleVert = false;
}
it seems to work one way if i click on toggleBrie, toggleVert switches off, but if toggleBrie is on toggleVert will not switch on and switch other off.
Let's look at the flow of your code. First you check if toggleVert is true. If it is, you change toggleBrie to false. When you get to the next statement "`if (toggleBrie == true)`" you've either just set toggleBrie to be false or it was not true to begin with. So you'll never fall into that expression. The better way to handle this problem is to determine this logic when one or the other is changed rather than, as I'm guessing you're doing, in Update/OnGUI/etc.
function SetVert (state : boolean)
{
if (state)
{
SetBrie (false);
}
toggleVert = state;
}
function SetBrie (state : boolean)
{
if (state)
{
SetVert (false);
}
toggleBrie = state;
}
And only use those functions to change the state of those values.
So, if you want to change the value with a GUI toggle element, just send the result of the Toggle function as the parameter.
This has been asked a while ago, I know, but I found an easier way than the one proposed and it may help other people looking for a solution (I had many toggles on same group):