I have two buttons button-A and button-B. If button-A in active position then button-B in detective position vice versa. please help me in code in java script unity. I have no ideas coming till now.
Something like that?
if(GUI.Toggle (new Rect(5, 70, 100, 30), canRotate, "Activate"))
canRotate=true;
if(GUI.Toggle (new Rect(5, 70, 100, 30), !canRotate, "Deactivate"))
canRotate = false;
Not sure if i got your question right. So you want two buttons like a radio-button-group where one 1 active the other not. The easiest way is to use Toggles. Depending on your desired behaviour one of those:
//version1
function OnGUI()
{
if (GUI.Toggle(new Rect(5, 70, 100, 30), canRotate, "Activate", "Button"))
{
canRotate = true;
}
if (GUI.Toggle(new Rect(5, 110, 100, 30),!canRotate, "Deactivate", "Button"))
{
canRotate = false;
}
}
//version2
function OnGUI()
{
canRotate = GUI.Toggle(new Rect(5, 70, 100, 30), canRotate, "Activate", "Button");
canRotate = !GUI.Toggle(new Rect(5, 110, 100, 30),!canRotate, "Deactivate", "Button");
}
Version 1 works like a true radio button group, so when you click one it gets active and if you click again it stays active.
Version 2 are just alternating toggles, so if you press either of the buttons they toggle the state
You probably want version 1.