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 ajotatxe · Jan 13, 2015 at 07:14 AM · uicollider

Clicks are detected through the UI elements

I have a scene with some 2D objects with colliders that detect clicks (OnMouseUpAsButton). I just have added a button and it seems to work (it changes its color when clicked, etc), but when the button is over one of the aforementionend 2D colliders, the click is detected by both elements.

How can this be avoided? That is, I want the click to be detected only by the element which is over; namely, the button.

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 HarshadK · Jan 13, 2015 at 07:38 AM 0
Share

Your button is using GUITexture or OnGUI or new UI 4.6?

avatar image ajotatxe · Jan 13, 2015 at 07:46 AM 0
Share

I have added it by the Unity menu and a 'canvas' and an 'eventSystem' were added, so I think that I am using 4.6 (I can't check it right now)

2 Replies

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

Answer by AndresBarrera · Jan 13, 2015 at 08:23 AM

I have not tested this yet, but maybe you could use the IsPointerOverGameObject function. I think your 2D colliders will work with an input system different from the UI EventSystem, and before you take actions on them you can check if the EventSystem is registering input on some UI element.

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 ajotatxe · Jan 13, 2015 at 09:32 AM 0
Share

After your answer I have the feeling that combining 2d colliders that receive mouse events with 4.6 UI objects it is not the usual way to work.

I'll read the documentation about the new EventSystem to learn the beaten path.

avatar image ajotatxe · Jan 18, 2015 at 08:14 AM 0
Share

I have finally done what you said to me. I have tried other possibilities and yours seems the simplest. And it works :)

avatar image
1

Answer by Juice-Tin · Jan 13, 2015 at 07:54 AM

For a sort of quick fix you can make a global variable.

 class Menu
 public static bool GuiClick;
 
 void OnGui(){
 GuiClick = false;
 
 if(button) GuiClick = true;
 }
 
 
 
 //Elsewhere...
 void Update(){
 if(Menu.GuiClick) return;
 
 //Game stuff
 }


This isn't tested, as the Gui will run at a different speed than Update, but it's worth a shot.

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

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

Help with Resolution / Scaling 0 Answers

Show panel when collide on prefabs 0 Answers

Blocking and not blocking input in new uGUI 4.6 1 Answer

How to stop collider from interfering with world space canvas? 1 Answer

UI image with collider doesn't work OnMouseDown 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