Creating lines between objects in scene view

Hi there!

I want to draw lines between GameObject hierarchy items depending on selection. So, if I select a GameObject in a hierarchy in scene view, lines should be drawn from the root object to the child objects recursively.

I already made the drawing part using OnDrawGizmos() and Gizmos.DrawLine().

My problem is, that I don’t know how to tell my script which GameObject is currently selected. My script is attached to a GameObject in the scene, so I cannot use Selection.activeTransform since it’s editor class. On the other hand, I cannot use an editor script, because that way it’s not drawing anything with Gizmos.DrawLine().

Is there a way to send messages from an editor script to a normal script?

Any help or suggestions would be appreciated!

Bump

Fixed

just wondering how you fixed this, could you post some code?

Sorry for the mega-late answer, here is my solution:

First I created an editor script that has a menu item. If you click on it, it instantiates a prefab that has the drawing script attached, and sends the current selection to this second script. The second script has to be in plugins folder.