I'm trying to draw a gizmo sphere at the location of each vertex in my mesh with the following code:
private void OnDrawGizmos()
{
MeshFilter selectedMeshFilter = (MeshFilter)objecttodraw.GetComponent("MeshFilter");
Mesh mesh = selectedMeshFilter.sharedMesh;
Vector3[] vertices = mesh.vertices;
Color[] colors = new Color[vertices.Length];
for (var i = 0; i <= vertices.Length; i++)
{
Gizmos.DrawSphere(vertices[i], vertices.Length);
}
}
I'm getting an exception, "Array index is out of range" on this line:
Gizmos.DrawSphere(vertices[i], vertices.Length);
IndexOutOfRangeException: Array index is out of range.
GetBounds.OnDrawGizmos () (at Assets/Scripts/GetBounds.cs:32)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)