Execute code only when object is selected in editor or scene view

I have a script to use only inside the editor.
How do I make code only run on a object that is selected / being moved around in the scene?

You should look into the examples and demos of extending the editor and the Editor class. I’m not that familiar with UnityScript, but a custom editor for one of your class should look like this:

// MyClassEditor.js
@CustomEditor (MyClass)
class MyClassEditor extends Editor
    function OnInspectorGUI ()
    function Update()
        // ...

Inside this class you have the target variable which holds the reference to the classinstance you’ve selected.

Note that Update isn’t called periodically. It is called when something changed (you moved the camera, an object). If you need a periodically event There’s also a delegate in EditorApplication

Ok got it figured out, OnSceneGUI() in a editor script can be used to do things when the specific object is selected in the scene.

I think you’d have to use another script

in C#:

if (Editor.target == ObjWithScript)
    ObjWithScript.GetComponent<ScriptName>().enabled = true;