Hi there, I have a scene with multiple GuiTextures in it. With a keypress they toggle on and off. Initially this works but my problem is that the gui textures are turned on and off individually during the game making the code not work. I need to be able to toggle all GuiTextures on and off at the same time with a keypress… Can anyone help? Here is the code I have on each GuiTexture.
guiTexture.enabled = false;
function Update() {
if (Input.GetKeyDown(KeyCode.F3)) {
guiTexture.enabled = !guiTexture.enabled;
}
}
if you want them all synchronous, try using a variable:
In One script as a controller:
static var guiOn : boolean;
if(Input.GetKeyDown(KeyCode.F3))
guiOn = !guiOn;
in the script attached to the texture objects:
if(controllerScript.guiOn)
guiTexture.enabled = true;
else
guiTexture.enabled = false;
Do you mean like this…?
var allOff : boolean = false ;
var gTxture : GUITexture[] ;
function Update(){
if(Input.GetKeyDown(KeyCode.F3))
ToggleTextures() ;
}
function ToggleTextures(){
gTxture = GameObject.FindObjectsOfType(GUITexture) ;
for(var i : int = 0 ; i < gTxture.length ; i++){
gTxture_.guiTexture.enabled = !gTxture*.guiTexture.enabled ;*_
alloff = !allOff ;
}
}