- Home /
How to make new UI button block raycasts
I've tried posting a question a few minutes ago but can't see it, sorry it if made a duplicate.
I'm trying to make a button with the new UI canvas, and choosing "Block Raycasts" does not block them, and I activate both the button and the elements in the scene under it.
I have tried adding colliders to my button.
I am working on a touch interface (for mobile) in a 2D project.
Thanks.
Have you tried using a layermask or adding a depth to the ray?
Thanks for the reply!
But it's still not working, I also tried looking for other posts on the subject, and got even more confused :\
I tried this simple line of code, and it just won't work when hovering on the elements (tried it with different parameters, 0, 1, -1, even though never really understood what that is supposed to mean anyway:
if(UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(0)) { Debug.Log ("Hovering!"); }
I'm sorry, I fell like this should be basic enough stuff for working with GUI to be able to fins answers online, but I'm really lost here, been stuck on this for a couple of days now...
Yes I did...
I'm sorry i'm still stuck on this...
because I don't really understand this properly I guess, I'm trying to use it in many places as well - Inside my Touch Input object, inside my UI element object, and with every parameter possible....
but nothing helps, it's either recognizing the whole canvas (and thus blocking the whole screen), or it is ignoring everything and the click on the UI isn't recognized.
If there was only a way to individually select the Canvas as "doesn't block raycast" and the UI buttons as "block ray casts" I think it would work... but I can't see any such option.
Have no Idea what I'm doing wrong... And that's even before I got to implementing it in the touch version, it's still in the editor and not working.
SOLVED!
So the problem was that I didn't realize the function return true only when the mouse clicked on the GUI, and not on mouse over, so check it at the wrong part of the code.
Thanks a lot for the help!
Answer by troien · Nov 19, 2014 at 11:47 AM
Do you mean blocking the rays that you cast yourself? If so, then this is a similar question.
Also, on the 4.6 beta forum, the faq actually covers this aswell.