Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question