I have an editor window with a GUI.Button in it
nothing special. when I left click the button I get the expected result , When I right click the button ,It still carries out a function.
private Rect rect;
private Event e;
void OnEnable()
{
rect = new Rect(0,0,200,40);
e = new Event();
}
void OnGUI()
{
//Do if you right click it will still output "Clicked"
if (rect.Contains(e.mousePosition) && e.type == EventType.MouseDown)
{
Debug.Log("Clicked");
}
}
The EventType “ContextClick” is an event that only applies to the UnityEditor and is only used in editor scripts as you can read in the docs. The MouseDown event is for any mouse button, including the second and third (usually the mousewheel-button). If you want to restrict it to some specific button you have to check the “button” field just like @Positive7 showed in his example.
Though I am using an editor window , this method seems to work best.