Anyone have a double-click script more reliable than mine?

Briefly, this script performs poorly enough to be non-viable. Any ideas for improvement or alternative approaches would be much appreciated.

var doubleClickStart = 0;

function OnMouseUp()
{

    if ((Time.time - doubleClickStart) < 0.4)
    {
        this.OnDoubleClick();
        doubleClickStart = -1;
    }
    else
    {
        doubleClickStart = Time.time;
    }
}

function OnDoubleClick()
{   
    // do some stuff.       
}

looks like you have a few minor bugs there, hopefully this will be a bit better

//start doubleClickStart as a float so no ambiguity to the compiler
var doubleClickStart : float = -1.0;
//EDIT TO DISABLE MOUSE CLICKS FOR A TIME AFTER DOUBLE CLICK
var disableClicks = false;
//END EDIT

function OnMouseUp()
{
    //EDIT TO DISABLE MOUSE CLICKS FOR A TIME AFTER DOUBLE CLICK
    if (disableClicks)
        return;
    //END EDIT

    //make sure doubleClickStart isn't negative, that'll break things
    if (doubleClickStart > 0 && (Time.time - doubleClickStart) < 0.4)
    {
        this.OnDoubleClick();
        doubleClickStart = -1;
            lockClicks();
    }
    else
    {
        doubleClickStart = Time.time;
    }
}

//EDIT TO DISABLE MOUSE CLICKS FOR A TIME AFTER DOUBLE CLICK
function lockClicks()
{
    disableClicks = true;
    yield WaitForSeconds(0.4);
    disableClicks = false;
}
//END EDIT

function OnDoubleClick()
{   
    // do some stuff.       
}

C# version->

	private float doubleClickStart = -1.0f;
	private bool disableClicks  = false;
    void OnDoubleClick()
	{   
		Debug.Log("Double Click");
		// do some stuff.       
	}

	IEnumerator lockClicks()
	{
		disableClicks = true;
		yield return new WaitForSeconds(0.4f);
		disableClicks = false;
	}
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
			if (disableClicks)
				return;
			
			if (doubleClickStart > 0 && (Time.time - doubleClickStart) < 0.4)
			{
				this.OnDoubleClick();
				doubleClickStart = -1;
				lockClicks();
			}
			else
			{
				doubleClickStart = Time.time;
		    }
	    }
    }

Try This One! I Created A simple double click script. I hope it Helps!

public bool firstClick=false;
public bool secondClick = false;
public int pressCount = 0;
// Use this for initialization
void Start () {
	
}


// Update is called once per frame
void Update () {
	
    
    if(firstClick == true)
    {
        Debug.Log("Start Of Coroutine");
        StartCoroutine(doubleClickTime());
    }
    else
    {
        pressCount = 0; // the press count will reset after the end of the coroutine
    }

}

public IEnumerator doubleClickTime()
{
    Debug.Log("Im Counting");
    yield return new WaitForSeconds(0.23f);
    if(pressCount >=2)
    {
        Debug.Log("Double Click!");
     // Do Some Awesome Things!
     
    }
    firstClick = false;

}

public void onClick()
{
    firstClick = true;
    pressCount++;
  

}