• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by CB-TV · May 18, 2013 at 10:02 AM · guitutorialinventory

DragWindowPosition Doesn't Work

My DragWindowPosition doesn't work. I was watching a tutorial: https://www.youtube.com/watch?v=W68rCj6baRk 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:

START:

 #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);
  
 //Textures
 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);
       //Name
       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));
             //Grid
             GridValue = GUI.SelectionGrid(Rect(GridPosition.x, GridPosition.y, GridSize.x, GridSize.y), GridValue, Grids, 5);
          GUI.EndScrollView();
  
          //Dragable Window
          GUI.DragWindow (Rect (WindowPosition.x, WindowPosition.y, 10000, 40));
       GUI.EndGroup();
    }
 }

END

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.

Comment
slayer29179

People who like this

1 Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fornoreason1000 · May 18, 2013 at 10:05 AM 0
Share

Please reformat your code by selecting all your code then press the code button,

avatar image CB-TV · Jun 05, 2013 at 06:59 PM 0
Share

I'll try resizing the DragWindowPosition in the script and see if it works

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by slayer29179 · May 26, 2013 at 03:28 PM

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. :) hope this helps!

Comment

People who like this

0 Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CB-TV · Jun 19, 2013 at 05:49 PM 0
Share

My thing is pretty fine now-it looks correct...but not the scroll bar. The scroll bar is not there? I've tried to resize it, position it but it just doesn't show up. Any ideas?

avatar image slayer29179 · Jun 19, 2013 at 05:52 PM 0
Share

Is your group big enough for it?

avatar image CB-TV · Jun 19, 2013 at 06:49 PM 0
Share

Errr...I dunno. What's a group lol-I'm just very new to scripting. Whenever I reposition the "ScrollPosition" variable it repositions all of the grids instead. I wondered if the script had errors where I put instead "GridPosition" instead of "ScrollPosition" but I didn't have any.

avatar image slayer29179 · Jun 20, 2013 at 06:04 AM 0
Share

The group is the BeginGroup line which makes a big group around everything you put in between that and GUI.EndGroup (kinda like a balloon with water inside)

The reason you put your grids inside of your scroll bar is to allow it to move with the scroll bar. When you move your grids position you are moving them inside the scroll bar. When you move the scroll bar you are moving both the grids and the scroll bar :)

avatar image CB-TV · Jun 22, 2013 at 05:06 PM 1
Share

Yeah, thanks, thats what it does!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

grid style inventory giving me "Index out of range" problems 1 Answer

Display Press E to Pickup when mouse over object 2 Answers

How to remove white border in Canvas? 1 Answer

Making a start screen in Unity 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges