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 DMCH · Feb 17, 2013 at 10:01 PM · 2donmousedown

Detecting Click on Object Issue

Hello!

I'm having some difficulty detecting clicks on a gameobject. Nothing happens when I click on the object, but after some experimenting, I found that the click is detected on other parts of the screen. These areas appear to change depending on where on the scene the camera is directed. The game is 2d, top-down, and the camera can scroll along x/z axes.

There is a GUI matrix on the scene, not sure if that might be linked to the problem.

Here's the code I'm using to detect clicks.

 void OnMouseDown()
     {
         Debug.Log("Pre-Scene check click detected " + Input.mousePosition);
         
         // Check if the Scene is 1
         if(sceneName == "1")
         {
             Debug.Log("Click detected");
         }
     }



Any help would be greatly appreciated. Let me know if you need any more info to solve this mystery!

Update 1

Added mouse position and Camera.main.ScreenToWorldPoint(mousePosition) to the debug. The y value of the ScreenToWorld is 65.8, whereas the turret is around 0.3. Could this have something to do with it? Image of debug below. alt text

onmousedown.png (6.7 kB)
Comment
Add comment · Show 4
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 Paulo-Henrique025 · Feb 17, 2013 at 10:15 PM 0
Share

After changing the gui matrix and doing your stuff restore it to the original, just is case.

avatar image DMCH · Feb 17, 2013 at 10:21 PM 0
Share

Thanks for suggestion. Disabled the GUI.$$anonymous$$atrix. Seems pretty much the same.

avatar image DMCH · Feb 17, 2013 at 10:54 PM 0
Share

Nail on the head. Thank you. A while back, I placed a plane over the camera intending to use it for a menu screen. If you'd like to convert to answer, we can close this one.

avatar image iwaldrop · Feb 18, 2013 at 12:32 AM 0
Share

Glad I could help; comment converted. Cheers!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by iwaldrop · Feb 17, 2013 at 10:45 PM

OnMouseDown does get a mouse click normally. If its not then mayber there is something that is physically getting in the way, or the object that you're trying to click doesn't have a collider.

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

11 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

Related Questions

2D Animation does not start 1 Answer

Collider priority with onMouseDown() 2 Answers

Need help with onMouseDown () 1 Answer

OnMouseDown working only sometimes 1 Answer

Script won't destroy prefab clones... 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