Using the DragWindow example from the scripting reference. Just modify the coordinates in the GUI update after they are set.
There’s probably a nicer way constrain the position. Haven’t really done anything with gui windows
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public Rect windowRect = new Rect(20, 20, 120, 50);
void OnGUI()
{
windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
// constrain the window rect x / y
windowRect.x = Mathf.Clamp(windowRect.x, 0, 300);
windowRect.y = Mathf.Clamp(windowRect.y, 0, 500);
}
void DoMyWindow(int windowID)
{
GUI.DragWindow(new Rect(0, 0, 10000, 20));
}
}