- Home /
Can't Drag GUI.Window's!!!
Now, I have a massive GUI script that is working so far, but the windows are not draggable at all. What I mean is, the windows are visible, and when you click their title bar the border turns white like it is supposed to, but I simply can't drag the windows around. Here is the code:
var doWindowWall : boolean = false; var doWindowMembrane : boolean = false; var doWindowCytoplasm : boolean = false; var doWindowRibosome : boolean = false; var doWindowER : boolean = false; var doWindowGolgi : boolean = false; var doWindowMitoC : boolean = false; var doWindowLysosomes : boolean = false; var doWindowMicTF : boolean = false; var doWindowCilFla : boolean = false; var doWindowNucleus : boolean = false; var doWindowVacs : boolean = false; var doWindowChlorpl : boolean = false; var doWindowChrompl : boolean = false; var doWindowVirus : boolean = false;
var iPadGladiator : Texture2D; var iPadGladiatorHighlight : Texture2D; var iPad2ndtexture : Texture;
private var wallRect = Rect (110,10,350,200); private var membraneRect = Rect (110,10,350,200); private var cytoRect = Rect (110,10,500,500); private var ribsRect = Rect (110,10,350,200); private var eRRect = Rect (110,10,500,500); private var golgiRect = Rect (110,10,350,200); private var mitoRect = Rect (110,10,350,200); private var lysoRect = Rect (110,10,350,200); private var micTFRect = Rect (110,10,500,500); private var cilFlaRect = Rect (120,10,500,500); private var nucleusRect = Rect (110,10,500,500); private var vacsRect = Rect (110,10,500,500); private var chlorplRect = Rect (110,10,350,200); private var chromplRect = Rect (110,10,350,200); private var virusRect = Rect (110,10,500,500);//variables
function OnGUI () { var iPad = GameObject.Find("iPad");
GUI.Box(Rect (0,0,110,300), "");
doWindowWall = GUI.Toggle (Rect (0,5,100,20), doWindowWall, "Cell Wall");
doWindowMembrane = GUI.Toggle (Rect (0,20,100,20), doWindowMembrane, "Cell Membrane");
doWindowCytoplasm = GUI.Toggle (Rect (0,35,100,20), doWindowCytoplasm, "Cytoplasm");
doWindowRibosome = GUI.Toggle (Rect (0,50,100,20), doWindowRibosome, "Ribosomes");
doWindowER = GUI.Toggle (Rect (0,65,100,20), doWindowER, "ER");
doWindowGolgi = GUI.Toggle (Rect (0,80,100,20), doWindowGolgi, "Golgi Bod.");
doWindowMitoC = GUI.Toggle (Rect (0,95,100,20), doWindowMitoC, "Mitochondria");
doWindowLysosomes = GUI.Toggle (Rect (0,110,100,20), doWindowLysosomes, "Lysosomes");
doWindowMicTF = GUI.Toggle (Rect (0,125,100,20), doWindowMicTF, "Micro T/F");
doWindowCilFla = GUI.Toggle (Rect (0,140,100,20), doWindowCilFla, "Cilia+Flag.");
doWindowNucleus = GUI.Toggle (Rect (0,155,100,20), doWindowNucleus, "Nucleus");
doWindowVacs = GUI.Toggle (Rect (0,170,100,20), doWindowVacs, "Vacuoles");
doWindowChlorpl = GUI.Toggle (Rect (0,185,100,20), doWindowChlorpl, "Chloroplasts");
doWindowChrompl = GUI.Toggle (Rect (0,200,100,20), doWindowChrompl, "Chromoplasts");
doWindowVirus = GUI.Toggle (Rect (0,215,100,20), doWindowVirus, "Virus");
if (GUI.Button(Rect(0,310,50,50), "Reset")) {
iPad.transform.rotation = Quaternion.identity;
iPad.transform.Rotate(0, 90, 270);
}
if (doWindowWall) {
GUI.Window (0, wallRect, DoWindowWall, "The Cell Wall");
}
if (doWindowMembrane) {
GUI.Window (1, membraneRect, DoWindowMembrane, "The Cell Membrane");
}
if (doWindowCytoplasm) {
GUI.Window (2, cytoRect, DoWindowCytoplasm, "The Cytoplasm");
}
if (doWindowRibosome) {
GUI.Window (3, ribsRect, DoWindowRibosome, "Ribosomes");
iPad.animation.Play("BoomBoom");
}
if (doWindowER) {
GUI.Window (4, eRRect, DoWindowER, "The ER");
}
if (doWindowGolgi) {
GUI.Window (5, golgiRect, DoWindowGolgi, "Golgi Bodies");
}
if (doWindowMitoC) {
GUI.Window (6, mitoRect, DoWindowMitoC, "Mitochondria");
}
if (doWindowLysosomes) {
GUI.Window (7, lysoRect, DoWindowLysosomes, "Lysosomes");
}
if (doWindowMicTF) {
GUI.Window (8, micTFRect, DoWindowMicTF, "Microtubules/Mictrofilaments");
}
if (doWindowCilFla) {
GUI.Window (9, cilFlaRect, DoWindowCilFla, "Cilia+Flagella");
}
if (doWindowNucleus) {
GUI.Window (10, nucleusRect, DoWindowNucleus, "The Nucleus");
}
if (doWindowVacs) {
GUI.Window (11, vacsRect, DoWindowVacs, "Vacuoles");
}
if (doWindowChlorpl) {
GUI.Window (12, chlorplRect, DoWindowChlorpl, "Chloroplasts");
}
if (doWindowChrompl) {
GUI.Window (13, chromplRect, DoWindowChrompl, "Chromoplasts");
iPad.animation.Play("BoomBoom");
}
if (doWindowVirus) {
GUI.Window (14, virusRect, DoWindowVirus, "A Virus");
}
}
function Update () { var iPad = GameObject.Find("iPad"); var rotatescript = iPad.GetComponent(Rotatescript); if (doWindowWall) { iPad.transform.Rotate(15 * Time.deltaTime, 0, 0); } if (doWindowMembrane) { //doWindowMembrane = false; iPad.transform.rotation = Quaternion.identity; iPad.transform.Rotate(0, 90, 0); } if (doWindowCytoplasm) { //None. Expressed as a picture. } if (doWindowRibosome) {
}
if (doWindowER) {
//None. Expressed as a picture
}
if (doWindowGolgi) {
iPad.transform.Rotate(15 * Time.deltaTime, 0, 0);
}
if (doWindowMitoC) {
iPad.transform.Rotate(15 * Time.deltaTime, 0, 0);
}
if (doWindowLysosomes) {
iPad.transform.Rotate(15 * Time.deltaTime, 0, 0);
}
if (doWindowMicTF) {
//None. Expressed as a picture.
}
if (doWindowCilFla) {
//None. Expressed as a picture.
}
if (doWindowNucleus) {
//None. Expressed as a picture
}
if (doWindowVacs) {
//None. Expressed as a picture
}
if (doWindowChlorpl) {
iPad.transform.Rotate(15 * Time.deltaTime, 0, 0);
}
if (doWindowChrompl) {
//None - Animation
}
if (doWindowVirus) {
//None. Expressed as a picture.
}
}
function DoWindowWall (windowID : int) { GUI.Label (Rect (10,20,320,170), "The Cell Wall ~ Casing of the iPad"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowMembrane (windowID : int) { GUI.Label (Rect (10,20,320,170), "The Cell Membrane ~ The Plug on the iPad"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowCytoplasm (windowID : int) { GUI.Label (Rect (10,20,320,170), "The Cytoplasm ~ Circuit Board"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowRibosome (windowID : int) { GUI.Label (Rect (10,20,320,170), "Ribosomes ~ App Store(Proteins ~ Apps)"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowER (windowID : int) { GUI.Label (Rect (10,20,320,170), "The ER ~ Wires on the Circuit Board"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowGolgi (windowID : int) { GUI.Label (Rect (10,20,320,170), "The Golgi Apparatus ~ Sync Wire"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowMitoC (windowID : int) { GUI.Label (Rect (10,20,320,170), "Mitochondria ~ Charging Wire"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowLysosomes (windowID : int) { GUI.Label (Rect (10,20,320,170), "Lysosomes ~ Program to Delete Files"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowMicTF (windowID : int) { GUI.Label (Rect (10, 20, 480, 350),iPadGladiatorHighlight); GUI.Label (Rect (10,270,320,170), "Microtubules and Microfilaments ~ Arms and Legs of Owner"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowCilFla (windowID : int) { GUI.Label (Rect (10, 20, 480, 350),iPadGladiator); GUI.Label (Rect (10,270,320,170), "Cilia and Flagella ~ The iPad's Owner"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowNucleus (windowID : int) { GUI.Label (Rect (10,20,320,170), "The Nucleus ~ The A4 Chip"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowVacs (windowID : int) { GUI.DragWindow (Rect (0,0,10000,10000)); GUI.Label (Rect (10,20,320,170), "Vacuoles ~ Flash Memory(Data ~ Materials)"); } function DoWindowChlorpl (windowID : int) { GUI.Label (Rect (10,20,320,170), "Chloroplasts ~ The Solar Powered iPad Charger"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowChrompl (windowID : int) { GUI.Label (Rect (10,20,320,170), "Chromoplasts ~ The iPad's Screen"); GUI.DragWindow (Rect (0,0,10000,10000)); } function DoWindowVirus (windowID : int) { GUI.Label (Rect (10,20,320,170), "Viruses ~ A jailbreaker on the iPad"); GUI.DragWindow (Rect (0,0,10000,10000)); }
Answer by Bampf · Mar 21, 2011 at 11:03 AM
I think the problem is that GUI.Window is returning a Rect, and your script is ignoring it.
(This would be similar to the way the GUI sliders pass back a new value, which you must save and use as the value the next time you call the slider function. If you don't, you are just displaying the original value again.)
So instead of
GUI.Window (13, chromplRect, DoWindowChrompl, "Chromoplasts");
Try
chromplRect = GUI.Window (13, chromplRect, DoWindowChrompl, "Chromoplasts");
BTW: if you want to make the whole window draggable just use
GUI.DragWindow()
without any parameter.
Yay!! Thanks for this info! I could not figure out why some of my windows would not drag and it was most certainly because I was not setting them to the value of their own rect. Once I did this, my problem was fixed.
Answer by Shadyfella13 · Feb 25, 2011 at 01:44 AM
have a look at GUI.DragWindow. This should do the trick.
http://unity3d.com/support/documentation/ScriptReference/GUI.html
Your answer
Follow this Question
Related Questions
Activate function when GUI.Window is drag into area 0 Answers
Drag windows Not working 1 Answer
Popup window size problem 1 Answer
Move one GUI window when another is moved? 0 Answers
How to open a separate window 1 Answer