# How do i Gizmos.drawLines in an order??

Hello i am trying to do this in Pic1, i tried doing it but get this(Pic2).

-Pic1
[78201-capture94.png*_|78201]

-Pic2
[78202-capture93.png*_|78202]
__

Here is the code so you know what i have done.

``````using UnityEngine;
using System.Collections;

public class Lines: MonoBehaviour {

public int xSize, zSize;
Vector3[] points;

void Start()
{
CreateLines();
}
private void CreateLines()
{
points = new Vector3[xSize * zSize];
for (int i = 0, z = 0; z < zSize; z++)
{
for (int x = 0; x < xSize; x++, i++)
{
points *= new Vector3(x, 0, z);*
``````

}
}

}
void OnDrawGizmos()
{
if (points == null)
{
return;
}
for (int i = 0; i < points.Length; i++)
{
Gizmos.DrawSphere(points*, 0.1f);*
}
for (int i = 0; i < points.Length-1; i++)
{
Gizmos.DrawLine(points*, points[(i + 1)]);*
}
}
}

*
*

If I didn’t mix up xSize and zSize, this should do it:

``````     for (int i = 0; i < points.Length-xSize; i++) {
Gizmos.DrawLine(points*, points[i + xSize]);*
``````

}

What I would do is create a function to draw connected points.

``````void DrawPoints (Vector3 points) {
for (int p = 0; p < points.Length; p++) {
Gizmos.DrawSphere(points[p], etc...);
if (p < points.Length-1) Gizmos.DrawLine(points[p], points[p+1]);
}
}
``````

And then call it in OnDrawGizmos.

``````float spacing = 1f;
int width = 3, height = 5;
private Vector3[] points;

void OnDrawGizmos () {
for (int x = 0; x < width; x++) {
points = new Vector3[height];
for (int y = 0; y < height; y++) {
points[y] = new Vector3(x*spacing, y*spacing, 0f);
}
DrawPoints(points);
}
}
``````

Yes, the points are being created every OnDrawGizmos, but there aren’t that many points, and if it was a problem, you could just have an array of arrays of points that you create in Start or wherever.
The main thing is the orientation. Just make sure that your for loops are inside each other correctly.