- Home /
Can I limit touch input for camera movement to non-ui areas?
Hi there
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.
Thank you for any help!
Answer by Fattie · Jun 09, 2013 at 11:25 AM
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
Thanks for the answer. Would I achieve this using raycasts? Or what method did you think of?
Yes, I'll do that!
It's working now as it should! fyi I use ScreenPointToRay
on the UI camera and mask the Raycast with the ui layer. Simple as that :) Please let me know if this is not a proper method in this case. Thank you for getting my work rolling again!
exactly, with a raycast
how you described it in your second comment is exactly what everyone does. Rock on !
Your answer
Follow this Question
Related Questions
canvas screen space camera rotation issue 0 Answers
rotate camera in android unity 1 Answer
Camera touch control script 1 Answer
Galak Z like UI element 0 Answers
Mobile touch input conflicts 1 Answer