DragWindowPosition Doesn't Work

My DragWindowPosition doesn’t work. I was watching a tutorial: Unity 3D Tutorial Part 31: Dragging GUI Windows - YouTube and it worked up until when I added the DragWindowPosition. When I played my game, the window was draggable but my Inventory buttons and Close button disappeared. It think this is a problem with the position or size of my GUI but I don’t know how to fix it. My script:


#pragma strict
//Private Variables
private var InventoryOn = false;
private var scrollBarChopGrid : Vector2 = Vector2.zero;
private var GridValue : float = -1;
//GUI Pos/Size
var NamePosition : Vector2 = new Vector2(30,30);
var NameSize : Vector2 = new Vector2(250,250);
var GridPosition : Vector2 = new Vector2(10,5);
var GridSize : Vector2 = new Vector2(323,410);
var ClosePosition : Vector2 = new Vector2(312,5);
var CloseSize : Vector2 = new Vector2(35,35);
var ScrollPosition : Vector2 = new Vector2(0,95);
var ScrollSize : Vector2 = new Vector2(355,500);
var WindowPosition : Vector2 = new Vector2(0,0);
var WindowSize : Vector2 = new Vector2(360,360);
var DragWindowPosition : Rect = Rect(0,0,WindowSize.x,WindowSize.y);
var InventoryWindow : Texture;
var CloseIcon : Texture;
var Grids : Texture [];
function Update () 
   //On or Off
   if (Input.GetKeyUp ("i"))
      if (InventoryOn == false)
         InventoryOn = true;
      else if (InventoryOn == true)
         InventoryOn = false;
         scrollBarChopGrid.y = 0;
   //Window Drag Fix
   if (Input.GetKeyDown("left shift"))
      if (Input.GetKeyDown("i"))
         DragWindowPosition.x = 10;
         DragWindowPosition.y = 10;
function OnGUI()
   if (InventoryOn ==true)
      DragWindowPosition = GUI.Window(0, DragWindowPosition, DoMyWindow, "");
function DoMyWindow(WindowID : int)
   if (InventoryOn == true)
      GUI.BeginGroup(new Rect(WindowPosition.x, WindowPosition.y, WindowSize.x, WindowSize.y), InventoryWindow);
      GUI.Label(Rect(NamePosition.x, NamePosition.y, NameSize.x, NameSize.y), "Your Inventory");
         //Close Button
         if (GUI.Button(Rect(ClosePosition.x, ClosePosition.y, CloseSize .x, CloseSize .y), CloseIcon))
            InventoryOn = false;
         //Scroll Bar
         scrollBarChopGrid = GUI.BeginScrollView(Rect (ScrollPosition.x, ScrollPosition.y, ScrollSize.x, ScrollSize.y), scrollBarChopGrid, Rect(0,0,0,420));
            GridValue = GUI.SelectionGrid(Rect(GridPosition.x, GridPosition.y, GridSize.x, GridSize.y), GridValue, Grids, 5);
         //Dragable Window
         GUI.DragWindow (Rect (WindowPosition.x, WindowPosition.y, 10000, 40));


Another thing wrong with the Inventory is that my Inventory Buttons go underneath the texture of the Inventory halfway through. This problem is only fixable, though, if I fix the first problem with the DragWindowPosition. I tried to explain this the best way I could but if you have any questions then please ask.

I just tried your code and it worked fine, straight away.

Take the script off your object.

Re-assign it.

Make sure you have assigned the Grids images, background image and close button image. :slight_smile: hope this helps!