Noah-1
1
Hello Guys, well I´ve been trying to deactivate a Gui button but I haven´t been able to do it yet. Here is an example of my problem:
if(Time.timeScale == 0) {
// Create button.
if (GUI.Button (Rect (115,100,250,50), "Options")) {
//Here I need to disable that button to bring up the options menu
//Then if options is clicked I disable it. Then I create a slider:
if(optionsOn)
camRotation = GUI.HorizontalSlider (Rect (40, 40, 150, 80), camRotation, 0.0, 35.0);
}
}
How can I easily disable the Gui button to bring up some other stuff?
Can you guys give me an example?
[Edit by Berenger : Code formatting]
This smells like a job for a state machine - maybe something like this:
private var state = 1;
private var option;
function OnGUI(){
if (Time.timeScale == 0){ // only shows options when timeScale is zero
switch (state){
case 1: // state 1 shows the first button:
if (GUI.Button(Rect(115,100,250,50), "Options"){ // when button pressed...
state = 2; // change to state 2...
option = 0; // and set invalid option value
}
break;
case 2: // state 2 shows the options:
if (GUI.Button(Rect(115,100,250,50), "Option 1") option = 1;
if (GUI.Button(Rect(115,120,250,50), "Option 2") option = 2;
if (GUI.Button(Rect(115,140,250,50), "Option 3") option = 3;
if (GUI.Button(Rect(115,160,250,50), "Option 4") option = 4;
if (option > 0) state = 3; // if any option set, change to state 3
break;
case 3: // state 3 shows the slider:
camRotation = GUI.HorizontalSlider (Rect (40, 40, 150, 80), camRotation, 0.0, 35.0);
// button Done finishes the cycle and returns to state 1:
if (GUI.Button(Rect(115,140,150,50), "Done") state = 1;
break;
}
}
}