- Home /
Adding different features to different GUI Windows...
I currently have 2 GUI Windows. I want to make one have a label and the other have a button.
Here is the script I'm using:(found off a tutorial)
var windowRect0 = Rect (20, 20, 120, 50);
var windowRect1 = Rect (20, 100, 120, 50);
function OnGUI () {
// Register the window. We create two windows that use the same function
// Notice that their IDs differ
windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "My Window");
windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "My Window");
}
// Make the contents of the window
function DoMyWindow (windowID : int) {
if (GUI.Button (Rect (10,20,100,20), "Hello World"))
print ("Got a click in window " + windowID);
// Make the windows be draggable.
GUI.DragWindow (Rect (0,0,10000,10000));
}
I don't really understand how to make a different window take a different part....
So how could I make my windowRect0 get the button and the windowRect1 get a label???
Answer by Mike 3 · Jun 27, 2010 at 01:14 AM
You'd either make two seperate DoMyWindow functions (So you'd call one from each Window function), or use a switch/if in the DoMyWindow function which decides what stuff to draw inside it
Edit (using the id to change behaviour):
in your DoMyWindow function:
switch(windowId) { case 0: //these case values would be better as defined variables so they can be changed //do something break;
case 1:
//do something
break;
}
How would I do the switch version? What would I put in the cases? Can you show me? Thanks.
Not sure I follow. the thing you're switching on is the variable passed to your function, and that's passed via the GUI.Window's first parameter. you just need to make sure you match up that parameter to the case
??? So how would I do it? Could you do one example code in a case so I know what to do? Thanks.
That's what the code already does - that code will work if you copy/paste it in (put the button code in //do something for case 0, label where //do something for case 1 is)