GUI Buttons getting a Double-click

I have an inventory and when you click an item once it displays the items info to the left and when you double-click it, the item gets equipped I was going to use something like this:

var ButtonClicked = false;

function OnGUI(){
    if(GUI.Button(Rect(10,10,50,50), "click me")){
        if(ButtonClicked){
            //EquipItem... and stuff
            ButtonClicked = false;
        }else{
            //DisplayItemInfo... and stuff
            ButtonClicked = true;
        }
    }
}

This seems extremely inefficient and it doesnt seem very efficient for an array which is what I’m using for my inventory courtesy of Der Dude and Sandor

All help will be awesome, Thanks!

You can use Event.clickCount to detect double clicks.

Event.ClickCount never worked for me. You suggested it in a similar thread, but when I debugged just to see if it worked, It never detected any clicks.

How did you use Event.clickCount in the script? It doesn’t detect clicks as such, but when you know a click has happened, it should tell you if another click happened immediately before (unless there’s a bug).

You should be able to use delta between clicks and if the time is < 1 or 2 seconds, then you have a decent double click event, that is all windows events do anyway for a double click, it is a hidden overload, same with a mac. You get the time between clicks and if it is < desired time, do event 2 else do event 1.

Sweet guys, I’ll look into both of your suggestions to see what I can get outa it.
Thanks!

I just ran into this problem. ‘clickCount’ is only valid when Event.current.type is EventType.MouseDown so you’ll need to store a temporary copy like so:

var clickCount;

...

if (Event.current.type == EventType.MouseDown)
    clickCount = Event.current.clickCount;
if (GUI.Button("click me")  clickCount == 2) {
    ...
}