# Window

> Make a popup window.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.IMGUIModule

## Window(int, Rect, WindowFunction, string)

Make a popup window.

```csharp
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, string text)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): ID number for the window (can be any value as long as it is unique).**** (\[Rect]\(/engine/6000.0/script-reference/unityengine/rect)): Onscreen rectangle denoting the window's position and size.**** (\[WindowFunction]\(/engine/6000.0/script-reference/unityengine/gui/windowfunction)): Script function to display the window's contents.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to render inside the window.

### Returns

| Type                                                        | Description                                                 |
| ----------------------------------------------------------- | ----------------------------------------------------------- |
| [Rect](/engine/6000.0/script-reference/unityengine/rect.md) | Onscreen rectangle denoting the window's position and size. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function that renders the GUI controls inside the window.

**Note:** If you are using [GUILayout](/engine/6000.0/script-reference/unityengine/guilayout.md) to place your components inside the window, you should use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). Also, if [MonoBehaviour.useGUILayout](/engine/6000.0/script-reference/unityengine/monobehaviour/useguilayout.md) is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click");
        }
    }
}
```

You can use the same function to create multiple windows. Just make sure that *each window has its own ID*. Example:

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void 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
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window " + windowID);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

```csharp
// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public bool doWindow0 = true;

    // Make the contents of the window.
    void DoWindow0(int windowID)
    {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }

    void OnGUI()
    {
        // Make a toggle button for hiding and showing the window
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

        // Make sure we only call GUI.Window if doWindow0 is true.
        if (doWindow0)
        {
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        }
    }
}
```

To make a window that gets its size from automatic GUI layouting, use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). **Call Ordering** Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the **Window** function), and retrieved when your DoWindow gets called: [GUI.skin](/engine/6000.0/script-reference/unityengine/gui/skin.md), [GUI.enabled](/engine/6000.0/script-reference/unityengine/gui/enabled.md), [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md), [GUI.backgroundColor](/engine/6000.0/script-reference/unityengine/gui/backgroundcolor.md), [GUI.contentColor](/engine/6000.0/script-reference/unityengine/gui/contentcolor.md), [GUI.matrix](/engine/6000.0/script-reference/unityengine/gui/matrix.md).

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void OnGUI()
    {
        // Here we make 2 windows. We set the GUI.color value to something before each.
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }

    // Make the contents of the window.
    // The value of GUI.color is set to what it was when the window
    // was created in the code above.
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window with color " + GUI.color);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

Note that you can use the alpha component of [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md) to fade windows in and out.

Additional Resources: [GUI.DragWindow](/engine/6000.0/script-reference/unityengine/gui/dragwindow.md), [GUI.BringWindowToFront](/engine/6000.0/script-reference/unityengine/gui/bringwindowtofront.md), [GUI.BringWindowToBack](/engine/6000.0/script-reference/unityengine/gui/bringwindowtoback.md).

## Window(int, Rect, WindowFunction, Texture)

Make a popup window.

```csharp
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, Texture image)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): ID number for the window (can be any value as long as it is unique).**** (\[Rect]\(/engine/6000.0/script-reference/unityengine/rect)): Onscreen rectangle denoting the window's position and size.**** (\[WindowFunction]\(/engine/6000.0/script-reference/unityengine/gui/windowfunction)): Script function to display the window's contents.**** (\[Texture]\(/engine/6000.0/script-reference/unityengine/texture)): Image to render inside the window.

### Returns

| Type                                                        | Description                                                 |
| ----------------------------------------------------------- | ----------------------------------------------------------- |
| [Rect](/engine/6000.0/script-reference/unityengine/rect.md) | Onscreen rectangle denoting the window's position and size. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function that renders the GUI controls inside the window.

**Note:** If you are using [GUILayout](/engine/6000.0/script-reference/unityengine/guilayout.md) to place your components inside the window, you should use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). Also, if [MonoBehaviour.useGUILayout](/engine/6000.0/script-reference/unityengine/monobehaviour/useguilayout.md) is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click");
        }
    }
}
```

You can use the same function to create multiple windows. Just make sure that *each window has its own ID*. Example:

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void 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
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window " + windowID);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

```csharp
// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public bool doWindow0 = true;

    // Make the contents of the window.
    void DoWindow0(int windowID)
    {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }

    void OnGUI()
    {
        // Make a toggle button for hiding and showing the window
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

        // Make sure we only call GUI.Window if doWindow0 is true.
        if (doWindow0)
        {
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        }
    }
}
```

To make a window that gets its size from automatic GUI layouting, use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). **Call Ordering** Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the **Window** function), and retrieved when your DoWindow gets called: [GUI.skin](/engine/6000.0/script-reference/unityengine/gui/skin.md), [GUI.enabled](/engine/6000.0/script-reference/unityengine/gui/enabled.md), [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md), [GUI.backgroundColor](/engine/6000.0/script-reference/unityengine/gui/backgroundcolor.md), [GUI.contentColor](/engine/6000.0/script-reference/unityengine/gui/contentcolor.md), [GUI.matrix](/engine/6000.0/script-reference/unityengine/gui/matrix.md).

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void OnGUI()
    {
        // Here we make 2 windows. We set the GUI.color value to something before each.
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }

    // Make the contents of the window.
    // The value of GUI.color is set to what it was when the window
    // was created in the code above.
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window with color " + GUI.color);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

Note that you can use the alpha component of [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md) to fade windows in and out.

Additional Resources: [GUI.DragWindow](/engine/6000.0/script-reference/unityengine/gui/dragwindow.md), [GUI.BringWindowToFront](/engine/6000.0/script-reference/unityengine/gui/bringwindowtofront.md), [GUI.BringWindowToBack](/engine/6000.0/script-reference/unityengine/gui/bringwindowtoback.md).

## Window(int, Rect, WindowFunction, GUIContent)

Make a popup window.

```csharp
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, GUIContent content)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): ID number for the window (can be any value as long as it is unique).**** (\[Rect]\(/engine/6000.0/script-reference/unityengine/rect)): Onscreen rectangle denoting the window's position and size.**** (\[WindowFunction]\(/engine/6000.0/script-reference/unityengine/gui/windowfunction)): Script function to display the window's contents.**** (\[GUIContent]\(/engine/6000.0/script-reference/unityengine/guicontent)): GUIContent to render inside the window.

### Returns

| Type                                                        | Description                                                 |
| ----------------------------------------------------------- | ----------------------------------------------------------- |
| [Rect](/engine/6000.0/script-reference/unityengine/rect.md) | Onscreen rectangle denoting the window's position and size. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function that renders the GUI controls inside the window.

**Note:** If you are using [GUILayout](/engine/6000.0/script-reference/unityengine/guilayout.md) to place your components inside the window, you should use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). Also, if [MonoBehaviour.useGUILayout](/engine/6000.0/script-reference/unityengine/monobehaviour/useguilayout.md) is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click");
        }
    }
}
```

You can use the same function to create multiple windows. Just make sure that *each window has its own ID*. Example:

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void 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
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window " + windowID);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

```csharp
// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public bool doWindow0 = true;

    // Make the contents of the window.
    void DoWindow0(int windowID)
    {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }

    void OnGUI()
    {
        // Make a toggle button for hiding and showing the window
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

        // Make sure we only call GUI.Window if doWindow0 is true.
        if (doWindow0)
        {
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        }
    }
}
```

To make a window that gets its size from automatic GUI layouting, use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). **Call Ordering** Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the **Window** function), and retrieved when your DoWindow gets called: [GUI.skin](/engine/6000.0/script-reference/unityengine/gui/skin.md), [GUI.enabled](/engine/6000.0/script-reference/unityengine/gui/enabled.md), [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md), [GUI.backgroundColor](/engine/6000.0/script-reference/unityengine/gui/backgroundcolor.md), [GUI.contentColor](/engine/6000.0/script-reference/unityengine/gui/contentcolor.md), [GUI.matrix](/engine/6000.0/script-reference/unityengine/gui/matrix.md).

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void OnGUI()
    {
        // Here we make 2 windows. We set the GUI.color value to something before each.
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }

    // Make the contents of the window.
    // The value of GUI.color is set to what it was when the window
    // was created in the code above.
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window with color " + GUI.color);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

Note that you can use the alpha component of [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md) to fade windows in and out.

Additional Resources: [GUI.DragWindow](/engine/6000.0/script-reference/unityengine/gui/dragwindow.md), [GUI.BringWindowToFront](/engine/6000.0/script-reference/unityengine/gui/bringwindowtofront.md), [GUI.BringWindowToBack](/engine/6000.0/script-reference/unityengine/gui/bringwindowtoback.md).

## Window(int, Rect, WindowFunction, string, GUIStyle)

Make a popup window.

```csharp
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, string text, GUIStyle style)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): ID number for the window (can be any value as long as it is unique).**** (\[Rect]\(/engine/6000.0/script-reference/unityengine/rect)): Onscreen rectangle denoting the window's position and size.**** (\[WindowFunction]\(/engine/6000.0/script-reference/unityengine/gui/windowfunction)): Script function to display the window's contents.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to render inside the window.**** (\[GUIStyle]\(/engine/6000.0/script-reference/unityengine/guistyle)): Style information for the window.

### Returns

| Type                                                        | Description                                                 |
| ----------------------------------------------------------- | ----------------------------------------------------------- |
| [Rect](/engine/6000.0/script-reference/unityengine/rect.md) | Onscreen rectangle denoting the window's position and size. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function that renders the GUI controls inside the window.

**Note:** If you are using [GUILayout](/engine/6000.0/script-reference/unityengine/guilayout.md) to place your components inside the window, you should use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). Also, if [MonoBehaviour.useGUILayout](/engine/6000.0/script-reference/unityengine/monobehaviour/useguilayout.md) is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click");
        }
    }
}
```

You can use the same function to create multiple windows. Just make sure that *each window has its own ID*. Example:

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void 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
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window " + windowID);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

```csharp
// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public bool doWindow0 = true;

    // Make the contents of the window.
    void DoWindow0(int windowID)
    {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }

    void OnGUI()
    {
        // Make a toggle button for hiding and showing the window
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

        // Make sure we only call GUI.Window if doWindow0 is true.
        if (doWindow0)
        {
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        }
    }
}
```

To make a window that gets its size from automatic GUI layouting, use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). **Call Ordering** Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the **Window** function), and retrieved when your DoWindow gets called: [GUI.skin](/engine/6000.0/script-reference/unityengine/gui/skin.md), [GUI.enabled](/engine/6000.0/script-reference/unityengine/gui/enabled.md), [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md), [GUI.backgroundColor](/engine/6000.0/script-reference/unityengine/gui/backgroundcolor.md), [GUI.contentColor](/engine/6000.0/script-reference/unityengine/gui/contentcolor.md), [GUI.matrix](/engine/6000.0/script-reference/unityengine/gui/matrix.md).

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void OnGUI()
    {
        // Here we make 2 windows. We set the GUI.color value to something before each.
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }

    // Make the contents of the window.
    // The value of GUI.color is set to what it was when the window
    // was created in the code above.
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window with color " + GUI.color);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

Note that you can use the alpha component of [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md) to fade windows in and out.

Additional Resources: [GUI.DragWindow](/engine/6000.0/script-reference/unityengine/gui/dragwindow.md), [GUI.BringWindowToFront](/engine/6000.0/script-reference/unityengine/gui/bringwindowtofront.md), [GUI.BringWindowToBack](/engine/6000.0/script-reference/unityengine/gui/bringwindowtoback.md).

## Window(int, Rect, WindowFunction, Texture, GUIStyle)

Make a popup window.

```csharp
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, Texture image, GUIStyle style)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): ID number for the window (can be any value as long as it is unique).**** (\[Rect]\(/engine/6000.0/script-reference/unityengine/rect)): Onscreen rectangle denoting the window's position and size.**** (\[WindowFunction]\(/engine/6000.0/script-reference/unityengine/gui/windowfunction)): Script function to display the window's contents.**** (\[Texture]\(/engine/6000.0/script-reference/unityengine/texture)): Image to render inside the window.**** (\[GUIStyle]\(/engine/6000.0/script-reference/unityengine/guistyle)): Style information for the window.

### Returns

| Type                                                        | Description                                                 |
| ----------------------------------------------------------- | ----------------------------------------------------------- |
| [Rect](/engine/6000.0/script-reference/unityengine/rect.md) | Onscreen rectangle denoting the window's position and size. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function that renders the GUI controls inside the window.

**Note:** If you are using [GUILayout](/engine/6000.0/script-reference/unityengine/guilayout.md) to place your components inside the window, you should use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). Also, if [MonoBehaviour.useGUILayout](/engine/6000.0/script-reference/unityengine/monobehaviour/useguilayout.md) is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click");
        }
    }
}
```

You can use the same function to create multiple windows. Just make sure that *each window has its own ID*. Example:

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void 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
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window " + windowID);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

```csharp
// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public bool doWindow0 = true;

    // Make the contents of the window.
    void DoWindow0(int windowID)
    {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }

    void OnGUI()
    {
        // Make a toggle button for hiding and showing the window
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

        // Make sure we only call GUI.Window if doWindow0 is true.
        if (doWindow0)
        {
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        }
    }
}
```

To make a window that gets its size from automatic GUI layouting, use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). **Call Ordering** Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the **Window** function), and retrieved when your DoWindow gets called: [GUI.skin](/engine/6000.0/script-reference/unityengine/gui/skin.md), [GUI.enabled](/engine/6000.0/script-reference/unityengine/gui/enabled.md), [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md), [GUI.backgroundColor](/engine/6000.0/script-reference/unityengine/gui/backgroundcolor.md), [GUI.contentColor](/engine/6000.0/script-reference/unityengine/gui/contentcolor.md), [GUI.matrix](/engine/6000.0/script-reference/unityengine/gui/matrix.md).

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void OnGUI()
    {
        // Here we make 2 windows. We set the GUI.color value to something before each.
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }

    // Make the contents of the window.
    // The value of GUI.color is set to what it was when the window
    // was created in the code above.
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window with color " + GUI.color);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

Note that you can use the alpha component of [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md) to fade windows in and out.

Additional Resources: [GUI.DragWindow](/engine/6000.0/script-reference/unityengine/gui/dragwindow.md), [GUI.BringWindowToFront](/engine/6000.0/script-reference/unityengine/gui/bringwindowtofront.md), [GUI.BringWindowToBack](/engine/6000.0/script-reference/unityengine/gui/bringwindowtoback.md).

## Window(int, Rect, WindowFunction, GUIContent, GUIStyle)

Make a popup window.

```csharp
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, GUIContent title, GUIStyle style)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): ID number for the window (can be any value as long as it is unique).**** (\[Rect]\(/engine/6000.0/script-reference/unityengine/rect)): Onscreen rectangle denoting the window's position and size.**** (\[WindowFunction]\(/engine/6000.0/script-reference/unityengine/gui/windowfunction)): Script function to display the window's contents.**** (\[GUIContent]\(/engine/6000.0/script-reference/unityengine/guicontent)): Text displayed in the window's title bar.**** (\[GUIStyle]\(/engine/6000.0/script-reference/unityengine/guistyle)): Style information for the window.

### Returns

| Type                                                        | Description                                                 |
| ----------------------------------------------------------- | ----------------------------------------------------------- |
| [Rect](/engine/6000.0/script-reference/unityengine/rect.md) | Onscreen rectangle denoting the window's position and size. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function that renders the GUI controls inside the window.

**Note:** If you are using [GUILayout](/engine/6000.0/script-reference/unityengine/guilayout.md) to place your components inside the window, you should use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). Also, if [MonoBehaviour.useGUILayout](/engine/6000.0/script-reference/unityengine/monobehaviour/useguilayout.md) is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click");
        }
    }
}
```

You can use the same function to create multiple windows. Just make sure that *each window has its own ID*. Example:

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void 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
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window " + windowID);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

```csharp
// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public bool doWindow0 = true;

    // Make the contents of the window.
    void DoWindow0(int windowID)
    {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }

    void OnGUI()
    {
        // Make a toggle button for hiding and showing the window
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

        // Make sure we only call GUI.Window if doWindow0 is true.
        if (doWindow0)
        {
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        }
    }
}
```

To make a window that gets its size from automatic GUI layouting, use [GUILayout.Window](/engine/6000.0/script-reference/unityengine/guilayout/window.md). **Call Ordering** Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the **Window** function), and retrieved when your DoWindow gets called: [GUI.skin](/engine/6000.0/script-reference/unityengine/gui/skin.md), [GUI.enabled](/engine/6000.0/script-reference/unityengine/gui/enabled.md), [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md), [GUI.backgroundColor](/engine/6000.0/script-reference/unityengine/gui/backgroundcolor.md), [GUI.contentColor](/engine/6000.0/script-reference/unityengine/gui/contentcolor.md), [GUI.matrix](/engine/6000.0/script-reference/unityengine/gui/matrix.md).

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);

    void OnGUI()
    {
        // Here we make 2 windows. We set the GUI.color value to something before each.
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }

    // Make the contents of the window.
    // The value of GUI.color is set to what it was when the window
    // was created in the code above.
    void DoMyWindow(int windowID)
    {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
        {
            print("Got a click in window with color " + GUI.color);
        }

        // Make the windows be draggable.
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
```

Note that you can use the alpha component of [GUI.color](/engine/6000.0/script-reference/unityengine/gui/color.md) to fade windows in and out.

Additional Resources: [GUI.DragWindow](/engine/6000.0/script-reference/unityengine/gui/dragwindow.md), [GUI.BringWindowToFront](/engine/6000.0/script-reference/unityengine/gui/bringwindowtofront.md), [GUI.BringWindowToBack](/engine/6000.0/script-reference/unityengine/gui/bringwindowtoback.md).
