- Home /
GUI Script switching on and off.
Hi all. If anyone could help me with this simple problem that would be great.
For my GUI, all of my buttons and windows and such are game objects with a texture script attached to them. When I disable the script in the inspector, the entire button disables- and this is exactly what I want for the functionality of my GUI.
So how do I write a script in "java preferably" to tell the button scripts to switch on or off in-game---"on mouse down or "on Mouse up" (for example) when I click a functional button?
Answer by spinaljack · Jun 09, 2010 at 10:14 PM
You can simply declare a boolean variable you can use to flag the on / off state e.g.
var active : boolean = true;
if(active && GUI.Button(Rect(someRect),"I am a button")){ //Do something }
This would make the button disappear entirely if active = false.
Alternatively if you wanted the button to stay visible but not do anything you can move the active statement nested inside the button statement:
if(GUI.Button(Rect(someRect),"I am a button")){
if(active){
//Do something
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613061749im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
switch scripts? 1 Answer
Load an image from www and save it for offline use 0 Answers
GetComponent Help 2 Answers
GUI in the middle of the screen 1 Answer