- Home /
Can't add script: The script is an editor script
Hi, i want to draw all the BoxColliders in the Scene while i'm creating it, so i created the script below to draw a box using the Gizmos utility.
using UnityEngine;
[ExecuteInEditMode]
public class ShowCollider : MonoBehaviour
{
// The Collider itself
private BoxCollider _collider;
void Start()
{
_collider = GetComponent<BoxCollider>();
}
void OnDrawGizmos()
{
Gizmos.color = Color.blue;
Gizmos.DrawCube(_collider.center,_collider.size);
}
}
The problem is that i can't add this script to any object because it is an "editor script". I'm a bit confused on how should i use an "editor script" because from the documentation it looks like you can add an "editor scripts" to gameobjects, there is a manual entry here where they add an "editor script" to an object to keep it oriented towards a certain direction.
My script is in the ./Asset/Editor folder.
So what am i doing wrong? My guess is that there is something wrong with the OnDrawGizmos function.
Answer by tanoshimi · Dec 30, 2016 at 01:29 PM
"My script is in the ./Asset/Editor folder"
That's where you're going wrong... put it in assets/scripts instead (or, in fact anywhere other than /editor) and it will no longer be an editor script.
What a silly, silly restriction... thanks for the heads up, though!