Skip to content

Instantly share code, notes, and snippets.

@qdx
Forked from Arakade/gist:9dd844c2f9c10e97e3d0
Last active November 22, 2020 08:39
Show Gist options
  • Save qdx/3215f4b14ef203dfaf7654ce3ed01c23 to your computer and use it in GitHub Desktop.
Save qdx/3215f4b14ef203dfaf7654ce3ed01c23 to your computer and use it in GitHub Desktop.
Call from OnDrawGizmos() to draw text at Unity3D glocal position in Editor
static void drawString(string text, Vector3 worldPos, Color? colour = null) {
UnityEditor.Handles.BeginGUI();
if (colour.HasValue) GUI.color = colour.Value;
var view = UnityEditor.SceneView.currentDrawingSceneView;
Vector3 screenPos = view.camera.WorldToScreenPoint(worldPos);
Vector2 size = GUI.skin.label.CalcSize(new GUIContent(text));
GUI.Label(new Rect(screenPos.x - (size.x / 2), -screenPos.y + view.position.height + 4, size.x, size.y), text);
UnityEditor.Handles.EndGUI();
}
void OnDrawGizmos()
{
#if UNITY_EDITOR
UnityEditor.Handles.color = Color.white;
UnityEditor.Handles.Label( pointA.position, "Point A" );
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment