Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: blitzer on March 19, 2014, 10:55:21 PM

Title: Trouble with OnClick Being Called Twice
Post by: blitzer on March 19, 2014, 10:55:21 PM
Hello everyone, I'm having trouble with using OnClick since it seems to happen 2 times for every button click. I've read this thread [http://www.tasharen.com/forum/index.php?topic=1636.0] but it does not address my problem (detailed below):

I've got a basic debugging script that allows me to jump my current spawn point forward or backwards by 1 on each click. However on click, the spawn jumps by 2 either forwards or backwards depending on the button logic. I have been using the spawn jump script for a while and I know it does work (and I can call these methods with keyboard presses as well and it works fine). So something is going on with OnClick, but I can't figure out what it is.

The scripts are is setup to work with both keyboard presses (to work on it in editor) and mouse/touch (for device testing and playing with the touch interface in editor). Please note, that I have tried disabling mouse / touch clicks on the Camera, it still happens twice on each click either way.

Any ideas or suggestions are appreciated.
Title: Re: Trouble with OnClick Being Called Twice
Post by: ArenMook on March 20, 2014, 12:55:54 AM
OnClick is a generic notification within NGUI.

The Button class also has an "On Click" notification you can set that triggers a remote function(s) as a result of this OnClick notification.

If you have an OnClick function being called as an "On Click" notification, then you will effectively call the function twice. Once from a generic NGUI event, and the second time from the button notification.
Title: Re: Trouble with OnClick Being Called Twice
Post by: blitzer on March 20, 2014, 01:02:16 AM
Sure enough, that was exactly what is happening. Thank you very much for the help.