O'Reilly logo

Extending Unity with Editor Scripting by Angelo Tadres

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting Scene View events

Most of the interaction with Level Creator is going to be performed through the mouse. In this section, will learn how to capture events in the Scene View.

Getting the mouse position

The Event class, part of the UnityEngine namespace, allows you to handle user inputs such as key presses or mouse actions.

Let's update the method EventHandler inside the LevelInspector class:

private void EventHandler() {
    HandleUtility.AddDefaultControl(
    GUIUtility.GetControlID(FocusType.Passive));
    
    Vector3 mousePosition = Event.current.mousePosition;
    Debug.LogFormat("MousePos: {0}", mousePosition);
}

The variable Event.current has the information about the current event that's being processed in the Scene View.

From current, we are accessing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required