Detect left click in scene view while in editor mode (tools scripting)

Hey there!

Trying to find information on how to detect if the mouse has clicked in the scene while in editor mode.
Struggling to find information on this, so was hoping someone here could give a pointer in the right direction :slight_smile:

For now I have tried this:

[CustomEditor(typeof(GridBuilder))]
public class InspectorGridBuilder : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        GridBuilder gridBuilder = (GridBuilder)target;

        if (GUILayout.Button("Build Grid"))
        {
            gridBuilder.BuildGrid();
        }

        Repaint();
    }

    private void OnSceneGUI()
    {
        Debug.Log("Running");

        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("Clicked");
        }
    }
}
1 Like
private void OnSceneGUI()
{
   Event e = Event.current;

   if(e.type == EventType.MouseDown)
   {
       // whatever
   }
}

I think? It’s similar to the old GUI.

1 Like

Thanks! That worked :slight_smile:

1 Like