First I have two cameras. One for the UI/HUD and the MainCamera both on different layers. I can control the camera by touch input - pinch to zoom and swipe to orbit. Now when I use the 2D UI elements/controls the camera also moves around because I am using the Input.GetTouch() method for the camera script. What I try to do is limit the touch input for the camera movement to “non-UI” areas so that the UI is in front and has priority.
I read about CullingMask but I don’t know how to use this to solve my problem.
Is there a way to “filter” the colliders of the UI? I always think this can not be that difficult, however I’m stuck.
Everyone hates this problem! There is no really good solution.
If Unity worked the “other” way, it would be just as bad.
I feel the simplest approach is:
in your ORBIT script. simply check if you are indeed hitting one of the colliders of the UI. if so, ignore it and do nothing.
if your UI is confined to a specific simple area (say “the top 1/4 of the screen”) … just make one collider called “UI exclusion zone”. and again in your game controls, just check if you are hitting that and if so, just ignore that touch.
Hope it helps
PS - I notice you are a new user. Be sure to “Tick” any useful answers please. You get points, and can this ask more questions in the future