- Home /
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.
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 :]
Okay Thanks, I'm Trying that out - should help with some things but maybe not alle. I'll be back ;)
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?
Okay, it also seems to behave different on mobile - i'll have to check this tomorrow.
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.
Answer by Duugu · Sep 02, 2015 at 03:10 PM
Are you using RaycastAll? How about just using Raycast?
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.