How do I register or read multiple MouseDown events ?

hey , I just creating a double click class which allows me to make anything clickable…

the code is written below .
this is done just by checking i a mouse down event is triggered twice in under 0.25 seconds.

then i realised that while i am not able to “click” anything… it is not really clicking the way buttons handle clicks .

I am checking for a mouse up event over the GUI element , setting a float to be realtimeSinceStartup then checking for a mouse down event , check if realtimeSinceStartup - the previously saved realtimeSinceStartup is less than 0.25 thus completing the double click.

but no buttons in unities gui even registers a mouse up event .

this code does check for double clicks on GUI elements… but not on GUI elements that already registers or read a MouseDown event somewhere in the unity API

 public class Click
    {
        static float time2;
        static bool result ;
        public static bool DoubleClick(Rect rect)
        {
            bool result = false;
            float time = Time.realtimeSinceStartup / 10.0f;
            if (rect.Contains(Event.current.mousePosition))
            {
                if (Event.current.rawType == EventType.MouseUp)
                {
                    time2 = time;

                }
                if (Event.current.rawType == EventType.MouseDown && time - time2 < 0.025f)
                {
                    time2 = 0;
                    result = true;
                }
            }
            return result;
        }


    }

Implementation example

   private Rect someRect =(new Rect(100,100,100,50));
private Rect someOtherRect = new Rect(250,100,100,50)
private Texture2D = (Texture2D) Resources.Load("someimage",typeof(Texture2D)); 
     void OnGUI()
     
     {
     GUI.Button(someRect,"double click me") ;
     if(Click.DoubleClick(someRect)) Debug.Log("double clicked")


GUI.DrawTexture(someOtherRect ,image);
      if(Click.DoubleClick(someOtherRect )) Debug.Log("texture clicked")
     
     }

The “old” GUI system handles events with the Event class. In your code you use some strange class called CurrentRawMouseEvent. If a control actually reacts to an event it “eats” that event so no other element can see it or react to it. Since you use GUI.Button, it will eat the MouseDown / MouseUp events. When an even got “eaten” Event.current.type will return “EventType.Ignore” instead of the actual event. You can use “Event.current.rawType” to get the actual event type.

ps: using hardcoded 0.025 seconds is not a good ides. First of all it’s pretty short. Usually the delay is longer. Also 0.025 will physically only work with at least 40 frames per second, though you would need more (80+) to guarantee that it’s working.

why dont you just use OnMouseUp/OnMouseDown event to register click and check time since last click?

speaking about your code… the question is WHERE and WHEN do you call your DoubleClick.DoubleClick() function?

your register first (and all others) click ONLY if you called DoubleClick from OnGUI when current event is MouseUp/MouseDown… do you really call it every OnGUI? in other words - its better to see a caller code.