I'm working on a scene with a lot of objects that are visually identical but which I need to see the game object name for. I looked at using the OnDrawGizmos() method, but there doesn't seem to be a Gizmos.DrawText or similar. Is there a way to write the object's name next to it in the scene editor view but not in the game?
See Handles.Label for information on how to draw text in the scene view.
Handles is an Editor class, so you'll need something like this in a script in your Editor folder (C#):
[DrawGizmo(GizmoType.SelectedOrChild | GizmoType.NotSelected)]
static void DrawGameObjectName(Transform transform, GizmoType gizmoType)
{
Handles.Label(transform.position, transform.gameObject.name);
}
Note that this adds a gizmo for every Transform in the scene, so it will show for every game object.
And for some other color:
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.red;
Handles.Label(transform.position, transform.gameObject.name, style);