- Home /
Disable game logic related input when touching NGUI objects
I'm implementing NGUI for my game, but ran to a problem. I have two cameras in my game, Main Camera is used to render the whole game world and another, GUI Camera, is to render NGUI. The game's movement is Point and Click so whenever player clicks somewhere, the Main Camera casts ray and game logic moves player to the collision point.
The problem: Whenever I click on any of the NGUI elements, the Main Camera also does it's logic of shooting the ray and getting new destination for the player.
What I'm after is this: Whenever player clicks on any of the GUI elements, the Main Camera understands it and doesn't shoot the ray to get new destination. Also, whenever any NGUI text field is being typed into, any other game world movement info doesn't get used. What is the usual way of handling it?
Answer by Denvery · Jun 28, 2014 at 08:59 PM
Hello!
Please assign the different layers for NGUI objects and game objects (about layers http://docs.unity3d.com/Manual/Layers.html).
For example, GUILayer for NGUI objects and Default layer for other objects. Then, in the Main camera use Culling mask = Default, and for GUI camera use Culling mask = GUILayer (about Culling mask read here:http://docs.unity3d.com/Manual/class-Camera.html).
Also you need to tune UICamera component(attached to the NGUI's camera) in the inspector: Event mask = GUILayer (read about event masks here: http://www.tasharen.com/?page_id=148).
Hope it will help a bit:-)
Thank you! I would like to upvote your answer but I do not have enough reputition :/