Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: pad406 on February 26, 2014, 12:42:40 PM

Title: Button firing click twice
Post by: pad406 on February 26, 2014, 12:42:40 PM
I noticed that a button I have was firing twice. After spending ages trying to figure out what I'd done, I created a new scene, added a 2D UI and created a lable to which I attached a collider and button script. Another simple script to Debug.Log("You clicked") and hey presto one click debug displayed twice. Some searching mentioned Unity Remote (not using that) and Event Sources on UICamera, so disabled all but Mouse. Still happening. Not really affecting my project but thought you might like to know. It may affect some.
Title: Re: Button firing click twice
Post by: ArenMook on February 26, 2014, 02:39:01 PM
On which target platform and what version of NGUI?
Title: Re: Button firing click twice
Post by: pad406 on February 26, 2014, 03:05:06 PM
NGUI 3.5.1 only update yesterday. Have tried on web, android and iOS, all them same. Steps taken to reproduce
Unity -> New Project
Only import NGUI
Create label
add collider
add button script
add my script
set notify
run

My script

using UnityEngine;
using System.Collections;

public class tstScript : MonoBehaviour
{

    public void OnClick()
    {
        Debug.Log("You clicked");
    }

}
Title: Re: Button firing click twice
Post by: ArenMook on February 26, 2014, 03:08:00 PM
Oh, well yeah that would do it.

OnClick is a generic NGUI event. It gets triggered regardless of whether you set the notification or not.

UIButton notification (On Click notification) is separate, and is itself using the NGUI OnClick event to trigger a remote function of your choice.

So the first time OnClick fires is because your script is being called directly by the NGUI event system. The second time it fires is because UIButton is calling it because you set it as the notification target.
Title: Re: Button firing click twice
Post by: pad406 on February 26, 2014, 04:14:19 PM
Ok, makes sense. I misunderstood that and thought you always had to set the notification, now I know better  ;D