Based on this tutorial: MESH GENERATION in Unity - Basics - YouTube

So to generate a quad I would first add the vetices and then the triangles.

``````void CreateShape()
{
vertices = new Vector3[]
{
new Vector3(0,0,0),
new Vector3(0,0,1),
new Vector3(1,0,0),
new Vector3(1,0,1)
};

triangles = new int[]
{
0, 1, 2,
1,3,2
};

}
``````

Now the question, the first triangle is between vertice 0, 1 and 2 and the second between 1, 3 and 2 but how do i know which number which vertice is? Are they numbered by the sequence I added them?

Whole code:

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

[RequireComponent(typeof(MeshFilter))]
public class MeshGenerator : MonoBehaviour
{

Mesh mesh;

Vector3[] vertices;
int[] triangles;

void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;

CreateShape();
UpdateMesh();
}

void CreateShape()
{
vertices = new Vector3[]
{
new Vector3(0,0,0),
new Vector3(0,0,1),
new Vector3(1,0,0),
new Vector3(1,0,1)
};

triangles = new int[]
{
0, 1, 2,
1,3,2
};

}

void UpdateMesh()
{
mesh.Clear();

mesh.vertices = vertices;
mesh.triangles = triangles;

mesh.RecalculateNormals();
}

}
``````

Look’s all good but have you got a mesh renderer on the object this script is attached to?

EDIT - sorry, forgot your original question. Yes, it’s the order you add to the array.

Your vertices are inside an Array, so Vertices[0] = new Vector3(0,0,0) Vertices[1] = new Vector3(0,0,1)