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 F-N · Jan 16, 2015 at 10:39 PM · c#physics2dcollider2dmouseposition

How can stuff not be working while it works in another script....

Hello everyone!

It looks like I just made one dumb mistake but heres the code that stands in 2 c# scripts but is working in only 1 script:

  if(Input.GetMouseButtonUp(0)){
         Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         Collider2D hitCollider = Physics2D.OverlapPoint(mousePos);
         
         if(hitCollider){
             if(hitCollider.name.Contains("menu")){
                 print ("I have just clicked a part of the menu!");
             }
             print (hitCollider.name);
         }
         else{
             print ("not detected any colliders :(");
         }
     }

The result in the first script is that it prints the name of the clicked collider whilst in the other script the result is that it prints "not detected any collider".

Note: maybe it is important to know that these two scripts are in two different unity projects. And I didnt forget to add a 2d collider! :P

thank you for even reading my question. Any help is appreciated!

Comment
Add comment · 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 richyrich · Jan 16, 2015 at 11:57 PM 0
Share

Don't know much about 2D. Could this be a Rigidbody requirement problem thing?

avatar image F-N · Jan 17, 2015 at 09:51 PM 0
Share

Nope, because in the project in which this stuff is working I dont have a Rigidbody assigned as well

1 Reply

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

Answer by W.Walter · Jan 17, 2015 at 12:48 AM

It may be to do with the Z positioning of the colliders. Make sure the colliders in both your project have the same z position just to check its not that. Also your code will not work with 3d colliders because your using the Phsics2D stuff in your script.

Comment
Add comment · Show 6 · 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 F-N · Jan 17, 2015 at 10:26 PM 0
Share

Both colliders are 2D and they have the same z position. There also isnt anything between the colliders and the camera

avatar image W.Walter · Jan 17, 2015 at 10:45 PM 0
Share

What about raycast layers. Check Project Settings>Physics for the collision matrix.

avatar image F-N · Jan 18, 2015 at 09:30 PM 0
Share

What do u exactly mean with this? In both projects all the available layers are set to true

avatar image F-N · Jan 18, 2015 at 09:40 PM 0
Share

I know wy it didnt work! It had to do with the Camera settings: I had to change this to Orthographic before it worked! I think it is weird though that Camera.main.ScreenToWorldPoint doesnt seem to work with the perspective camera settings. W.Walter, do you know how to achieve the same result with the perspective Projection setting?

avatar image F-N · Jan 19, 2015 at 09:27 PM 0
Share

I think I just mark your answer as fine so that it's clear that this question got a answer :P

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.

Follow this Question

Answers Answers and Comments

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Edge Collider issue 1 Answer

why Raycast2D doesn't work properly? 0 Answers

OnTriggerExit2D Does not work 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