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 Iampeen · Jan 25, 2012 at 01:05 AM · dragdrag-and-droprelease

Input.GetMouseButtonUp(0) not detected after drag

Hi! I'm working on an implementation of a toolbar where you drag the item from your inventory onto the previous rect that the GUI has painted. But I'm having difficulty getting unity to recognize mouse release. It seems to work fine with GetMouseButton() but of course I'd prefer on release than on drag. I can't seem to see why GetMouseButton() would differ from GetMouseButtonUp() in this instance. Any help is greatly appreciated!

 var item = inventoryScript.GetDraggedItem();
 if(Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && item != null){
     print("Reaching here is fine!");
     if(Input.GetMouseButtonUp(0)){
         print("It never reaches here :(");
         inventorySlot[number] = item;
     }
     
     /* This works, but is on drag instead of release
     if(Input.GetMouseButton(0)){
         inventorySlot[number] = item;
     }
     */
 }
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 syclamoth · Jan 25, 2012 at 01:31 AM

The problem is here:

 if(Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && item != null)

key point: Event.current.type == EventType.Repaint.

Releasing the mouse creates a 'MouseUp' event, which is obviously not the same as a Repaint event. This means that the mouse can never be in the process of getting released at the same time as you are in a Repaint Event!

Change this to

 if(Event.current.type == EventType.MouseUp && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && item != null)

and use Event.button instead of Input.GetMouseButton, since you already know that the mouse was released.

In general, using Input.GetMouseButton inside of GUI code is a bad idea, because the GUI stuff gets called at a different rate and rhythm from the Update stuff that the Input class is designed to be used with.

Comment
Add comment · Show 3 · 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 syclamoth · Jan 25, 2012 at 01:33 AM 0
Share

Better still, you could skip the 'Event.current.type' stuff entirely, and just use

 if (Event.current.button == 0)
 {
     // do clicky stuff
 }
avatar image Iampeen · Jan 25, 2012 at 02:21 AM 0
Share

Oh I see, thanks.

I changed to EventType.$$anonymous$$ouseUp but it's not entering the conditional? It appears as though the current event seems to never be $$anonymous$$ouseUp?

avatar image syclamoth · Jan 25, 2012 at 03:17 AM 0
Share

Have you tried testing for just the $$anonymous$$ouseUp without testing the GetLastRect bit as well? It's possible that because of the way the GUILayout works, that part isn't working properly now.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help debugging: SiblingIndex 0 Answers

uGUI - How to listen for Slider-Handle release? 1 Answer

Drag and drop files from the assets folder to another folder not working 0 Answers

Unable to spawn and drag via button click 1 Answer

Unity 4.6: Drag and drop 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