M
M
Mimocodil2021-11-25 15:58:13
Unity
Mimocodil, 2021-11-25 15:58:13

How to draw the locations of points on the scene?

My component has a list of points of type Vector3[]. Now I set them manually, but it is inconvenient and not very visual. I want that when a new point is added and moved on the stage, a label visible only to the editor appears with a label corresponding to the index of the point in the array. How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NoNameDeveloper, 2021-11-25
@Ezekiel4

OnDrawGizmos - Documentation to help

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Vector3[] Points;
    [SerializedField] private float _sphereRadius = 1;
    [SerializedField] private float _sphereColor = new Color32(0, 150, 255, 255);

    // Methods

    private void OnDrawGizmos()
    {
        Gizmos.color = _sphereColor;

        for(int i = 0; i < Points.Length; i++)
        {
            // Draw a yellow sphere at the transform's position.
            Gizmos.DrawSphere(Points[i], _sphereRadius);
            Handles.Label(Points[i], $"Point {i}");
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question