- Home /
Close a GUI.Toggle when another opens in a different script?
Hello all. I have multiple GUI.Toggles on different scripts that when opened, change the camera view to the relevant camera in each script. This works great, but despite my best efforts they are all able to be opened, and when a second is open after the first, it disables the buttons within the Rect opened in the toggle. Here is one example, but there are about ten of these scripts on different objects in the scene. Can anyone point me in the right direction to close them? I use a doWindow function to change them, but need other scripts to tell each of the other doWindows to close when another is opened. Of course just camera.enabled= false kills the camera but does not switch back.
here is one:
#pragma strict
var oldValue : boolean = true;
var doWindow0 : boolean = true;
var sound : AudioClip;
var camera1 : Camera;
var camera2 : Camera;
function Start(){
camera1.enabled = true;
camera2.enabled = false;
}
function DoWindow0 (windowID : int) {
if (GUI.Button (Rect (10,20,100,80), "Offline")) {
audio.PlayOneShot(sound);
}
if (GUI.Button (Rect (10,110,100,80), "Repair")) {
audio.PlayOneShot(sound);
}
}
function OnGUI () {
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.yellow;
if (LaunchSatellite.satLive == true) {
oldValue = doWindow0;
doWindow0 = GUI.Toggle (Rect (1800,20,120,50), doWindow0, "Satellite View");
if (oldValue != doWindow0) {
camera1.enabled = !doWindow0;
camera2.enabled = doWindow0;
}
if (doWindow0) {
GUI.Window (0, Rect (1800,50,120,200), DoWindow0, "");
}
if (LaunchSatellite.satLive == false) {
camera1.enabled = true;
camera2.enabled = false;
}
}
}
and another
#pragma strict
var oldValue : boolean = true;
var doWindow0 : boolean = true;
var sound : AudioClip;
var camera1 : Camera;
var camera2 : Camera;
public static var moneyLow = false;
public static var moneyNorm = false;
public static var moneyHigh = false;
function Start(){
camera1.enabled = true;
camera2.enabled = false;
}
function DoWindow0 (windowID : int) {
GUI.Label (Rect (10,20,180,80), "Set Shipment Quantity") ;
GUI.Label (Rect (120,50,270,80), "Send the smallest shipment for the least return. 6 Ore / 3000 Credits per shipment") ;
if (GUI.Button (Rect (10,50,100,40), "Least"))
moneyLow = true;
moneyNorm = false;
moneyHigh = false;
if (moneyLow == true)
GUI.Label (Rect (400,60,70,80), "Selected") ;
GUI.Label (Rect (120,120,270,80), "Send the normal shipment for the average return. 4 Ore / 6000 Credits per shipment") ;
if (GUI.Button (Rect (10,120,100,40), "Normal"))
moneyLow = false;
moneyNorm = true;
moneyHigh = false;
if (moneyNorm == true) {
GUI.Label (Rect (400,130,70,80), "Selected") ;
}
}
function OnGUI () {
GUI.backgroundColor = Color.red;
GUI.contentColor = Color.yellow;
oldValue = doWindow0;
doWindow0 = GUI.Toggle (Rect (20,260,120,50), doWindow0, "Mining");
if (oldValue != doWindow0) {
camera1.enabled = !doWindow0;
camera2.enabled = doWindow0;
}
if (doWindow0) {
GUI.Window (0, Rect (140,260,500,400), DoWindow0, "Ore Processing Menu");
}
}
Any help you can provide would be most appreciated. Thanks for reading.
In the end I had to put every window into a single script, and have a bool for each set to false until it was opened. When one was opened and thus true, I then made all the others false. It works but it's messy and long.
Your answer
Follow this Question
Related Questions
Whats wrong with my GUI.Toggle? 2 Answers
Is there a multiple selection ugui toggle group? 1 Answer
3 sets of button activations GUI 1 Answer
GUI toggle on click, unless on GUI. 1 Answer