0
\$\begingroup\$

I have a window called "red window" on scene1. When i click on the hello world button it should displays another window called green window and the first window should invisible. How it possible.

using UnityEngine;
using System.Collections;![alt text][3]

 public class window : MonoBehaviour {
 private bool render = false;
 public Rect windowRect0 = new Rect(20, 20, 120, 50);
 public Rect windowRect1 = new Rect(20, 100, 120, 50);
 void OnGUI() {
     GUI.color = Color.red;
     windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");
     GUI.color = Color.green;
    windowRect1 = GUI.Window(1, windowRect1, DoMyWindow1, "Green Window");
 }
 void DoMyWindow(int windowID) {
     if (GUI.Button (new Rect (10, 20, 100, 20), "Hello World")) {
         }



       //GUI.DragWindow(new Rect(0, 0, 10000, 10000));
   }
  void DoMyWindow1(int windowID) {
 if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
     print("Got a click in window with color2222222222 " + GUI.color);
 //GUI.DragWindow(new Rect(0, 0, 10000, 10000));
 }

enter image description here

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Use a bool. Just have a boolean value that gets flipped when the first button is pressed:

using UnityEngine;
using System.Collections;![alt text][3]

 public class window : MonoBehaviour 
 {
     private bool render = false;
     private bool redWindow = true;
     public Rect windowRect0 = new Rect(20, 20, 120, 50);
     public Rect windowRect1 = new Rect(20, 100, 120, 50);
     void OnGUI() 
     {
         GUI.color = Color.red;
         windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");
         if( !redWindow )
         {
             GUI.color = Color.green;
             windowRect1 = GUI.Window(1, windowRect1, DoMyWindow1, "Green Window");
         }
     }
     void DoMyWindow(int windowID) 
     {
         if (GUI.Button (new Rect (10, 20, 100, 20), "Hello World")) 
         {
              redWindow = false;
         }



         //GUI.DragWindow(new Rect(0, 0, 10000, 10000));
     }
     void DoMyWindow1(int windowID) 
     {
         if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
         print("Got a click in window with color2222222222 " + GUI.color);
         //GUI.DragWindow(new Rect(0, 0, 10000, 10000));
     }

So, you click the button, and the other one is added to the GUI.

\$\endgroup\$
2
  • \$\begingroup\$ :Thanks for ur answer sir....ok but the first window is not invisible why? \$\endgroup\$ Nov 26, 2014 at 8:04
  • 1
    \$\begingroup\$ Put the other window in a if block with the opposite condition. I suggest you study this more if you don't understand this, no offence. \$\endgroup\$
    – Ben
    Nov 26, 2014 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .