Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Deepestblue on April 28, 2013, 03:16:48 PM

Title: ButtonClicks going "through" GUI?
Post by: Deepestblue on April 28, 2013, 03:16:48 PM
Hi there,

I am still in the process to get into NGUI, and after adding my first panels I saw that apparently clicking an NGUI-button doesn't only send the click event to the button but also to everything below it. In my case a button e.g. destroys a gameobject A and as the panel is right over it suddenly gameobject B right behind A gets selected with the same click. Is there a way to tell NGUI to consider this click-event "done" after a button was pressed?

Thanks for the help!
Title: Re: ButtonClicks going "through" GUI?
Post by: ArenMook on April 28, 2013, 03:31:36 PM
You either need to fully rely on an NGUI event system, or check UICamera.hoveredObject if you're relying on Input checks.
Title: Re: ButtonClicks going "through" GUI?
Post by: Deepestblue on April 28, 2013, 03:34:58 PM
Thanks for the quick answer. I guess I have a little reading to do then to understand the NGUI event system completely. :)
Title: Re: ButtonClicks going "through" GUI?
Post by: Deepestblue on April 29, 2013, 05:50:48 AM
Hm, I don't seem to get it. I add an onClick() function to my GameObject and "treat" the inside like I would have with an NGUI-button, but the function doesn't seem to be called. Do I have to add anything else to my GameObject to "listen" to the NGUI Event system?

Thanks!
Title: Re: ButtonClicks going "through" GUI?
Post by: ArenMook on April 29, 2013, 06:22:43 PM
You need a collider for it to receive an OnClick event.
Title: Re: ButtonClicks going "through" GUI?
Post by: Deepestblue on April 30, 2013, 01:58:51 AM
Well, yes of course. It is rather that the NGUI event system doesn't seem to work for anything that's not on the NGUI layer. E.g. if I just drop

void OnHover (bool isOver) { Debug.Log (gameObject.name); }

on any GameObject on my default layer (and yes, the objects have colliders too) nothing is happening. That's why I asked if  I have to do anything else to activate the NGUI event system for my clickable objects in the game world to "fully rely on the NGUI event system". Oout of obvious reasons I can't have my entire game on the NGUI layer ...
Title: Re: ButtonClicks going "through" GUI?
Post by: ArenMook on April 30, 2013, 07:31:51 AM
1. The object must have a collider.
2. The camera that sees the object must have a UICamera script on it.
3. The UICamera's event mask must have the object's layer covered.
Title: Re: ButtonClicks going "through" GUI?
Post by: Deepestblue on May 01, 2013, 02:03:21 AM
Duh! I didn't know the world-camera had to have the UICamera component too! That was it. Thanks a lot for your help! :)