ExecuteInEditMode and OnSceneGUI

My goal is to create a script that places some blocks using raycast directly in my scene view. Like some kind of level editor.

But since I keep failing I wanted to start very very simple. I just want to create a script that writes x into the console everytime any kind of input like moving the mouse or anything like this comes to the editor view. But even this script is not printing x:

#pragma strict

@script ExecuteInEditMode;

function OnSceneGUI ()

What am I doing wrong?

OnSceneGUI is a callback that only exists in custom inspectors which are editor scripts. You seem to have a normal runtime script (MonoBehaviour). ExecuteInEditMode just makes a normal runtime script to have it’s normal callbacks called even in edit mode.

You can use MonoBehaviour.OnDrawGizmos or OnDrawGizmosSelected to simply draw some stuff in the scene view. However if you want to use some more advanced functions that the editor provides you should create either a custom inspector for a certain runtime class or an editor window. A custom inspector can implement OnSceneGUI which is called while that object is selected in the inspector.

An EditorWindow can use the SceneView.onSceneGUIDelegate event and hook some function to it. It all depends on your needs and for what and how your tool should be used.

You might want to check this Tutorial :