Author Topic: Trouble with OnClick Being Called Twice  (Read 1862 times)

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Trouble with OnClick Being Called Twice
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trouble with OnClick Being Called Twice
« Reply #1 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.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Trouble with OnClick Being Called Twice
« Reply #2 on: March 20, 2014, 01:02:16 AM »
Sure enough, that was exactly what is happening. Thank you very much for the help.