How do you block duplicate events?

I am trying to implement a simple toggle button working with Unity3D iPhone and the event code is always being called twice.

In this example, guiTexture.enabled is set to True and then immediately to False when button clicked once.

How do you get around this? How can you detect when a duplicate event is processed? It looks like a duplicate event is occurring.

function OnGUI () {
    buttonRect.x = (transform.position.x * Screen.width);
    buttonRect.height = guiTexture.pixelInset.height / 2;
    buttonRect.y = (transform.position.y * Screen.height) + buttonRect.height;
    buttonRect.width = guiTexture.pixelInset.width;
    buttonRect.height = guiTexture.pixelInset.height / 2;
    if (Event.current.type == EventType.MouseDown) {
    	if (buttonRect.Contains(Event.current.mousePosition)) {
    		guiTexture.enabled = !guiTexture.enabled;
    		print("set to " + guiTexture.enabled);

Is the Gui system on iphone different from the normal GUI? Otherwise you would just do something like `if (GUI.Button(rect, text, texture){ do something }`

I suspect, that you handle the mouseDown event twice somehow by doing this manually.

Certainly things like mouse down will fire as often as the update, or in this case, GUI event fires.

One way is to use buttons, as described above, or use mouseup instead of mousedown.

You can also slow the acting of the click down by ignoring some

    public void OnGUI () {    {
    // Display your objects and get input
	// Display...
	// if mouse up, etc -- ActOnClick();	   	

float nextFire=0;
float fireRate = .5f;

public void ActOnClick()
    if (Time.time < nextFire)
    nextFire = Time.time + fireRate;
    // Act on Click

I use this quite bit. You can adjust your fire rate to determine how much you want to ignore for.

I know this is a bit old but here is a solution that seems to work on all browsers:

if (event.stopPropagation)
} // if
	event.cancelBubble = true;
} // else