Label with text, the child number

 [SerializeField] float waypointRadius = 1f;

    private void OnDrawGizmos()
        for (int i = 0; i < transform.childCount; i++)
            Gizmos.color =;
            // Draw a label with the child index next to the sphere
            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.white;
            // Offset the label in the y-axis to ensure it's in front of the sphere plus play with x and z to your liking, maybe add serialized fields for x,y,z
            Vector3 labelPosition = transform.GetChild(i).position + new Vector3(-.5f, 0.5f, -0.1f);
            Handles.Label(labelPosition, i.ToString(), style);

            Gizmos.DrawSphere(transform.GetChild(i).position, waypointRadius);


1 Like

There’s just one issue with that. Handles is coming from the UnityEditor namespace so you can’t have it in a build version of the game.

But then, all these visualizations for the patrol paths are only visible in the Scene View and belong into the editing realm of the project, and therefore will eventually have to be put into an Editor sub-folder and namespace, anyway.

There will likely be some visualizations that are part of the game-play too (for example placing a marker on the target position the player is moving), too. While they might be using OnDrawGizmos() they would not be using the Gizmos.Draw...() methods, though.

Privacy & Terms