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 Joshua Falkner · Jul 29, 2010 at 05:54 PM · bugbehaviouronmouseup

Does OnMouseUp() require OnMouseDown() to be triggered first?

This might be a bug, or I may just be looking at this wrong, but here's the behavior I'm seeing. I want to be able to click the mouse somewhere on the screen (not over my target) and drag the mouse over the target object. When I let go of the mouse button, I'd like things to happen. On my target object I have a script attached with this:

function OnMouseUp() {
   print("Your Mouse button is up!");
}

Pretty simple. Yet, when I click somewhere on the screen, drag my mouse on top of the object, and then let the button go nothing happens. If I click the mouse down on top of my target and then let it go it works correctly. I assume this is because when my mouse is clicked while over the target it fires the OnMouseDown() function.

I've worked around the issue by setting a variable to true when OnMouseEnter() is triggered, and then in the update() I test is the variable is true && the GetMouseButtonUp(0).

function OnMouseEnter() { mouseIsOver = true; }

function Update() { if(mouseIsOver) { if(Input.GetMouseButtonUp(0)) { print("Your mouse button is up!"); } } }

Is this a bug, or am I missing something really obvious?

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
1
Best Answer

Answer by jacksmash2012 · Jul 29, 2010 at 06:00 PM

From the documentation:

"OnMouseUp is only called if the mouse was pressed down while over the same GUIElement or Collider."

http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseUp.html

So perhaps it's because you're moving the mouse before releasing the mouse button that you're not getting the expected behavior?

Comment
Add comment · Show 2 · 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 Joshua Falkner · Jul 29, 2010 at 06:05 PM 0
Share

I figured the answer was right in front of me! Guess my reading comprehension isn't what it used to be!

avatar image qJake · Jul 29, 2010 at 06:53 PM 0
Share

If this doesn't work for you, you need to code a custom raycast or detection inside of Update(), with GetButtonUp("mouse 0"). This will work no matter what, but you need to check if the cursor is over the object you want.

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

No one has followed this question yet.

Related Questions

OnMouseDown() intended behaviour 1 Answer

NullReferenceException when looking at target in an Editor class (CustomEditor) 2 Answers

Asset store crash 2 Answers

Space Invaders style game bug. 1 Answer

BUG? Camera rotation on x set to 90! 0 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