I’m kind of new working with Unity, and I was wondering what is a quick and easy way to determine whether a button is visible or not visible.
I am making an interface where if you click one button, that button disappears, and three new buttons appear that give new functionality.
I’ve tried running in states, but it seems that GUI functions can only run in the OnGUI function.
Any tips?
Hello!
Using a flag to activate or deactivate the button. like this:
var showButton : boolean = true;
function OnGUI(){
if(showButton){
if(GUI.Button(Rect(0,0,50,50),"Button"){
Debug.Log("Clicked the button, deactivating it");
showButton = false;
}
}
}
Hope it helps you
Hello!
Using a flag to activate or deactivate the button. like this:
var showButton : boolean = true;
function OnGUI(){
if(showButton){
if(GUI.Button(Rect(0,0,50,50),"Button"){
Debug.Log("Clicked the button, deactivating it");
showButton = false;
}
}
}
Hope it helps you
I actually tried that initially, and am not getting the desired effect. Are you sure this works?
edit: Nevermind, it does work. Doesn’t seem to work in a loop determined by a “toggle” button however.
yes, if the showButton var is false, you are not going to be able the button. I’m totally sure of it.
What effect are you getting?, can you show me screenshots on how is it behaving when you do that?
yes, if the showButton var is false, you are not going to be able the button. I’m totally sure of it.
What effect are you getting?, can you show me screenshots on how is it behaving when you do that?
Sorry, edited my post too early before checking my other control loops.
It seems that when the if statement is in a loop where a “toggle” button determines the entry into the loop, that it fails.
actually it does not fail the toggle, the thing is that because of the speed the instructions are executed, you dont see the button toggling
This doesn’t seem to be working anymore. At least when I click the button, it doesn’t go away when the bool check is turned to false. It “was” working before, not sure what changed. AFAIK, nothing.
var bShowMenu : boolean = true;
function OnGUI () {
//Phone Pickup Button
bShowPhone = GUI.Toggle(Rect(200,250,100,100), bShowPhone, "Phone Icon");
// Make a group on the center of the screen
GUI.BeginGroup (Rect (Screen.width / 2 - 250, Screen.height / 2 - 250, 400, 600), "Phone Placement");
//Draw Phone
if( bShowPhone ) {
GUI.Box(Rect(1,1,360,800), bgImage);
}
if (bShowMenu) {
if( GUI.Button (Rect (55,50,110,100), "Messages") ) {
Debug.Log("Show Messages Menu");
bShowMenu = false;
}
}
GUI.EndGroup();
}
for some reason, that script you posted works for me…
var bShowMenu : boolean = true;
var bShowPhone : boolean = true;
function OnGUI () {
//Phone Pickup Button
bShowPhone = GUI.Toggle(Rect(200,250,100,100), bShowPhone, "Phone Icon");
// Make a group on the center of the screen
GUI.BeginGroup (Rect (Screen.width / 2 - 250, Screen.height / 2 - 250, 400, 600), "Phone Placement");
//Draw Phone
if( bShowPhone ) {
GUI.Box(Rect(1,1,360,800), "TEST");
}
if (bShowMenu) {
if( GUI.Button (Rect (55,50,110,100), "Messages") ) {
Debug.Log("Show Messages Menu");
bShowMenu = false;
}
}
GUI.EndGroup();
}
This is how i changed to make it work… and as you can see i didnt changed anything… it works, check the images.
after pressing the button…
Yeah something is goofy.
I have an idea though.
What OS are you running? I’m on Vista 64. I’m willing to bet you’re on a 32 Bit OS.
It seems that Vista causes a lot of errors in Unity, at least in the development environment.
I may have to downgrade to Windows XP to get around this unless a Unity update is released to handle these errors.
Then you should report it as a bug,
can you make a small project that reassembles that issue and also provide screenshots of how is behaving?, as it would really help the developers understanding the issue and fixing it so it works better on Vista 64