|
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?
(comments are locked)
|
|
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. You didn't specify what you want to do when the object is selected. OnSceneGUI is a gui callback that allows you to render GUI elements inside the SceneView. OnSceneGUI is like OnGUI called for different events. For a general purpose you should use Update().
Mar 26 '12 at 01:35 AM
Bunny83
(comments are locked)
|
|
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: 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 I doesn't appear that
Apr 01 '12 at 11:24 PM
Ipsquiggle
Well i mixed up the different Update callbacks. EditorWindow has an Update callback: EditorWindow.Update. However editor funcionality shouldn't be used in MonoBehaviour components since they go into the build and can't contain Editor functions unless they are surrouned with You can still use the update delegate in any editor classes. Use OnEnable and OnDisable to attach / detach the delegate.
Apr 02 '12 at 01:08 AM
Bunny83
(comments are locked)
|
|
I think you'd have to use another script in C#: I can't add this code anywhere in JS without having a compile error. tried my update function, tried the editor script for my script. if(Editor.target == transform) An instance of type 'UnityEditor.Editor' is required to access non static member 'target'.
Mar 25 '12 at 07:53 AM
Bluestrike
This example is in C# and not in UnityScript(JS). I can't find any hint in your two sentences that you're using UnityScript. Furthermore this fragment indeed doesn't make much sense to me ;)
Mar 25 '12 at 11:16 AM
Bunny83
(comments are locked)
|
