- Home /
Script with in-game and in-editor part
Hi,
I have a simple script, which uses a circular area to spawn stuff in. It would be very useful that the script could draw this circle in the editor.
I found '@script ExecuteInEditMode()' though this would make the entire script run in edit mode right? Which isn't what I want. In editor mode it should only draw the circle, not spawn enemies, and ingame it should only spawn the enemies, not draw the circle. (I also don't want different script, since then I would have to keep their radius in sync, which sucks.)
Any suggestions?
Thanks!
Answer by rutter · Apr 12, 2012 at 07:44 PM
Sounds like you might be interested in `MonoBehaviour.OnDrawGizmos()` or `OnDrawGizmosSelected()`. Check out the `Gizmos` class to see what you can draw. Sounds like DrawWireSphere()
might be just what you need.
(It is possible to fake a circle by drawing a bunch of lines between various points in a rough circle around your object, but that's a little trickier.)
Thanks! The DrawWireSphere isn't perfect, but man very close! Plus, some nice magic I didn't know about yet :D Thanks, you solved my thingy on a very elegant way, and you learned me something new!
Thanks :D