- Home /
No resolution
Execute unattached script in Edit Mode
This should be pretty simple. I'm trying to draw a sphere around each spawn point in the scene during edit mode but can't seem to get it to work. I put this script into the Editor folder…
@script ExecuteInEditMode()
function OnDrawGizmos ()
{
var spawns = GameObject.FindByTag("SpawnPoints");
var cc = spawns.transform.childCount;
for (var i=0; i < cc; i++)
{
// Display the spawning radius
Gizmos.color = Color.white;
Gizmos.DrawWireSphere ( spawns.transform.GetChild(i).transform.position, 5.0);
}
}
and gizmos are only in edit mode anyway, not sure why you need to implicitly tell it to run in edit. unless im misunderstanding the question
I was trying to avoid having the script exist in the scene. I don't want it to get included when the project is exported, hence why I'm trying to make it an editor script.
OnDrawGizmos is only called on $$anonymous$$onoBehaviours. You need an object in the scene to benefit from it.
If you are worried about multiple scripts running in builds, you can use Platform Dependent Compilation : http://docs.unity3d.com/Documentation/$$anonymous$$anual/PlatformDependentCompilation.html
eg : this is one of my gizmo scripts :
#pragma strict
#if UNITY_EDITOR
function OnDrawGizmos()
{
var col : BoxCollider = GetComponent.< BoxCollider >();
if ( col )
{
Gizmos.color = Color.red;
Gizmos.matrix = transform.localToWorld$$anonymous$$atrix;
Gizmos.DrawCube( col.center, col.size );
}
}
#endif
Edit : If you are interested in how optimal this method might be, I just asked a question you may want to follow. Now I'm curious how efficient this may be : http://answers.unity3d.com/questions/495342/questions-about-platform-dependent-compilation.html