# How to procedurally create an extruded cube mesh's indicies?

I'm working on a tool that allows the user to create rails(basically an extruded cube) by placing 3d points where the vertices of rail would be. The picture below shows what I'm talking about. The orange points being the user placed points and the black points being the vertices created around it. I can create the vertices just fine the problem comes from creating the indices for the rail.

I tried using a for loop that goes through the user place points and creating the triangle indices by using i as an offset for each indices, but it using vertices that didn't exist for indices. Here's the code for the vertex and indices creation.

    List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
for (int i = 0; i < points.Count - 1; i++)
{
Vector3 forward = -(points[i] - points[i + 1]).normalized;
Quaternion rotation = Quaternion.LookRotation(forward);

//bottom left
vertices.Add(transform.InverseTransformPoint(points[i] + rotation * (-transform.up - transform.right)));
//top left
vertices.Add(transform.InverseTransformPoint(points[i] + rotation * (transform.up - transform.right)));
//top right
vertices.Add(transform.InverseTransformPoint(points[i] + rotation * (transform.up + transform.right)));
//bottom right

vertices.Add(transform.InverseTransformPoint(points[i] + rotation * (-transform.up + transform.right)));
}

for(int i=0; i<points.Count-1; i++){
//left face

//top face

//right face

//bottom face