Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by upariver · Nov 05, 2016 at 04:52 PM · triggerlayermaskclick objectsclickable

C# 2D Click on Object touching trigger

How can I click on an object that is touching a trigger?

The current issue is that it just recognizes the trigger, and since the objects are intertwining, it only recognizes one of them, being this case the trigger.

I am using both as I need to create a click area and a non click area.

Could anyone point out on what I could use? Thanks in advance.

Comment
Add comment · Show 6
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 upariver · Nov 10, 2016 at 10:04 AM 0
Share

Bump, see if anyone has any suggestions.

avatar image snorcack upariver · Nov 10, 2016 at 11:16 AM 0
Share

You can use custom raycasts with masks to detect the clicks while ignoring objects that are not required. If you can give some more information (screenshots / layout), it might be easier to suggest something. Cheers !

avatar image upariver snorcack · Nov 10, 2016 at 02:21 PM 0
Share

http://imgur.com/a/IAqS7

Thanks for the help so far! Can you understand it with this image?

Show more comments
avatar image upariver · Nov 11, 2016 at 12:29 PM 0
Share

I have updated it with a imgur link @snorcack

avatar image upariver · Nov 17, 2016 at 11:25 AM 0
Share

Bump, see if I get something.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by snorcack · Nov 11, 2016 at 01:12 PM

Based on the image provided, I am giving a basic solution with certain assumptions. 1 - The green object and the trigger have some sort of script or tag that can differentiate it. 2 - These are sprites and not canvas objects.

Attach a script to green object that calls your onclick function. Put in a bool that sets true or false on the "OnTriggerExit" and "OnTriggerEnter" methods.

Do a custom "GetRayIntersectionAll" to get all the 2d colliders at the mouseclick. If you get the green object, call the onclick function on it. If it had entered the trigger, the bool would be false and the function would not be called.

Let me know if this is in the direction you wanted or if I have oversimplified things for myself.

Comment
Add comment · Show 1 · 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 upariver · Nov 14, 2016 at 04:10 PM 0
Share

Hello again, and thanks for the help so far. I am having an issue with getting Unity to even recognize my Layermasks. I have a on mouseClick and am trying to get a hit only on the prefabs of the greenObject type, which is Layer$$anonymous$$ask 8. So I tried:

However I am not getting any results. The click works as I have tested , however it does not recognize the prefabs of "greenObject". Could you tell me whats wrong?

 void Update()
     {
         if(Input.Get$$anonymous$$ouseButtonDown(0))
         {
             Ray r = gCamera.ScreenPointToRay(touchPosition);
             RaycastHit hit;
             
             if (Physics.Raycast(r, out hit, $$anonymous$$athf.Infinity, 1<<8))
             {
              
 
 
                 Debug.Log("greenObject");
         
             }
         }

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

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

Related Questions

Need help making parts of an image clickable. 1 Answer

How can I change image when click Icon? 1 Answer

Collider trigger two times, even if it's not active. 1 Answer

OnTriggerEnter2D being called 25 times. 0 Answers

Gameobject doesnt move after build 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