Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 fschaar · Sep 02, 2015 at 12:03 PM · uiraycastonclick

physics.raycast troubles with onClick UI Events

OK, I made a Game which uses physics raycast to control objects with colliders in the scene. I also have some UI objects for menu items , mixt with 3d objects arranged as menu items. My Problem is now, that I use physics raycast as well as the ui Event system. so if i click a UI button, the raycast fires as well, so if i click a button, there is also an interaction with tho collider objects behind it.

What is the best way to handle such situations?

At the moment I have the touch Behavior seperate for each object in my szene, so that sthe raycast is fired for alle objects active - maybe that could cause a problem to. Is it better to handle all controls in one Event or make events for all Objects that can recive one?.

I have no strict plan how to handle this.

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

2 Replies

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

Answer by huloo · Sep 02, 2015 at 06:12 PM

Hi

You can reference to this thread

http://answers.unity3d.com/questions/784617/how-do-i-block-touch-events-from-propagating-throu.html

and this nice video :]

https://www.youtube.com/watch?v=EVZiv7DLU6E

Comment
Add comment · Show 4 · 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 fschaar · Sep 02, 2015 at 07:00 PM 0
Share

Okay Thanks, I'm Trying that out - should help with some things but maybe not alle. I'll be back ;)

avatar image fschaar · Sep 02, 2015 at 08:03 PM 0
Share

Okay, now I can separate the differnt inputs. I completely removed onClick events and handled everything with rays manually. It is still complicated because i have to use raycastall, but so far it works.

But i still have problems with two finger gestures. it always puts a one finger gesture at the end and the beginning of the two hand gesture. The reason may be, that you never hit both fingers exactly the same time. is there a workaround for this?

avatar image fschaar · Sep 02, 2015 at 08:11 PM 0
Share

Okay, it also seems to behave different on mobile - i'll have to check this tomorrow.

avatar image kkrac · Apr 29, 2017 at 06:34 PM 0
Share

this doesn't work.

I have used solution 3 for a clickable inventory menu. But on the other hand, I have a script with Input.Get$$anonymous$$ouseButtonDown for the player to move and it ALWAYS gets triggered.

avatar image
0

Answer by Duugu · Sep 02, 2015 at 03:10 PM

Are you using RaycastAll? How about just using Raycast?

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 fschaar · Sep 02, 2015 at 06:04 PM 0
Share

The Problem is, I don't really understand what is happening. I use something like this:

  private Ray TouchClickRay;
  private RaycastHit HittedObject;
   ...
  TouchClickRay = ObjectContext.currentCamera.ScreenPointToRay (position);
 
         
         if (Physics.Raycast (TouchClickRay, out HittedObject)) {
             
             if (HittedObject.collider.gameObject.name ==
 ...

This obviously also works through the GUI, which is not wanted. how do I prevent this? The Rays also seem to hit multiple objects. Even if i use 3D Objects for GUI, the objects under them seem to be affected. I don't really understand how these things work together.

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

32 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

Related Questions

Correct use of transform.position of UI element into game screen 1 Answer

OnClick triggers twice because of UnityEngine.SendMouseEvents 0 Answers

How to click on irregular buttons in new ui 4 Answers

New UI - Ignore raycast where alpha is 0 2 Answers

Raycast on ui elements not working? 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