Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by HuskyPanda213 · Mar 18, 2014 at 05:56 PM · guiinputpositionbug

Scrollview with Input.MousePosition?

How do you make the Input.MousePosition fit with a GUI.ScrollView? Right now the drag/drop system does not work in my game, I found the problem, but I cannot seem to find a solution. I just can't. The problem is that the Input.MousePosition does not work with GUI group things(even worse with scrollviews). So how would I fix this? P.S: InputManagerClass.mousePosition is just a getter with Input.MousePosition.x, and Input.MousePosition.y - Screen.height.

Thanks in advance!

Code:

 private void RenderInventory(int id){
         //GUI.BeginGroup (inventoryWindow);
         ScrollPosition = GUI.BeginScrollView (new Rect (inventoryWindow.x + 0,inventoryWindow.y + 19,395,225), ScrollPosition, new Rect (0,0,370,1161));//Scrollfield.
         int cnt = 0;//Location of the current item in loops.
         for(int y = 0; y < inventoryCols; y++){//Y
             for(int x = 0; x < inventoryRows; x++){//X
                 if(cnt < myItems.Count){//If the item exists.
                     if(myItems[cnt].itname != null && myItems[cnt].itname.Length > 1){//If not null/bugged.
                     
                         Rect rect = new Rect(3+x * 46.5f,y * 46.5f,45,45);
                         GUI.Label(rect,"" + myItems[cnt].itname,inventoryButton);
 
                         if (rect.Contains(InputManagerClass.mousePosition))
                         {
                             Debug.Log("Contains MOUSE!!!");
                             if (Event.current.type == EventType.MouseDown)
                             {
                                 OnCurrentDragStart(myItems[cnt]);
                             }
                         }
 
                         //if(Event.current.type == EventType.MouseUp && currentDrag != null){
                         //    OnCurrentDragDrop(myItems[cnt]);
                         //}
 
                     }
                     //If bugged/null.
                     else{
                         //If this is null/bugged, Remove.
                         myItems.Remove(myItems[cnt]);
                     }
                 }
                 //If does not exist.
                 else{
                     GUI.Label(new Rect(3+x * 46.5f,y * 46.5f,45,45),"",inventoryButton);
                 }
                 //Increase the current loop item.
                 cnt++;
             }
         }
         GUI.EndScrollView ();//End the scrollfield
         //GUI.EndGroup ();
     }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by zharik86 · Mar 18, 2014 at 06:55 PM

If you want to use coordinates of a mouse in the OnGUI function, you shall use Event.current.mousePosition, instead of Input.mousePosition. But don't forget that Event.current will be bound on coordinates to BeginGroup or to Scroll. I.e. for computation of a real line item it will be necessary to add still coordinates of the upper left corner of the container if, of course, it is.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

unity 5.2 Input.GetTouch(0).position incorrect? 3 Answers

GUI.TextField - Android: Unfocusing with click instead of Ok-button causes critical error 0 Answers

v4.6 UI Element's Positioning Incorrect 1 Answer

Coordinates of Input.GetTouch(0).position vs Screen coordinates? 1 Answer

Input.mousePosition returns coordinates as integers. 1 Answer


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