- Home /
Select object by selecting gizmo or handle?
Is it possible to select a gameobject by selecting the gizmo in the Scene View? I have a line (Gizmos.DrawLine) between object A and object B and I want to be able to select the line and have it select object A.
That then leads on to my second question to grab a MouseOver event from gizmos, but maybe i'll leave that for another Question.
Answer by Tom 17 · Apr 19, 2011 at 01:12 PM
This question is old, so I don't know if I will be of help anymore, still I'm going to answer.
I don't know if gizmos are meant to be selectable, but on the other hand there is the possebility of extending the Unity Editor itself (refer Extending the Editor). There you get the idea of how to use handles to easily modify certain aspects of your object A.
That doesn't help you on your specific question, as basically to see the handles you would have to have your object selected allready. So as another straw for to hold on here is a small editor script that automatically selects the parent of something selected in the scene or hierachy view:
using UnityEditor; using UnityEngine; [@CustomEditor(typeof(AutoSelectParent))] public class AutoSelectParentEditor : Editor { public override void OnInspectorGUI() { EditorGUILayout.TextArea("You should not see this text unless this script doesn't work"); }
public void OnSceneGUI()
{
MonoBehaviour handle = (MonoBehaviour)target;
GameObject[] selection = new GameObject[1];
selection[0] = handle.transform.parent.gameObject;
Selection.objects = selection;
}
}
put that script in an Editor folder for it to work. The following script is rather a marker to objects that shall not be selected. Put it outside an Editor folder and attach it to an object. Whenever you try to select object C that is a child of object A, you will instead select A immediatly. This can become a nuisance if you DO want to select object C again. To do that type the name ob object C in the search filter of the scene view to exclude the parent and you CAN select object C again.
using UnityEngine; public class AutoSelectParent : MonoBehaviour { }
Maybe you get some different ideas from the hints I gave you - if you do ponder this problem anymore, anyhow :-)
Your answer
Follow this Question
Related Questions
Permanent handles (when object is not selected) 1 Answer
What is the best way to fix texture z-fighting? 5 Answers
Editor Windows : Help required 1 Answer
Draggable Nodes in Editor? 1 Answer
Showing Handles in the Game View 1 Answer