Jump to content
    public Vector3[] vertices = new Vector3[100];
    // Use this for initialization
    void Start () {
        Mesh ground = new Mesh();
        vertices = new Vector3[size * size];
        int[] triangles = new int[600];
        filter = GetComponent<MeshFilter>();
        Vector2[] uvs = new Vector2[vertices.Length];

        int i = 0;

        for (int x = 0; x < size; x++)
        {
            i = x * size;
            for (int y = 0; y < size; y++)
            {
                vertices[i] = new Vector3(y,0,x);
                i++;
            }
            i = 0;
        }
        for (int k = 0; k < size; k++)
        {
            for (int j = 0; j < size; j++)
            {
                Debug.Log(i);
                triangles[i] = j*(k * size) + 1;
                i++;
                triangles[i] = j*(k * size) + 1;
                i++;
                triangles[i] = j*(k * size) + size;
                i++;
            }
        }

     
        
        ground.vertices = vertices;
        ground.triangles = triangles;

        filter.mesh = ground;

    }

    // Update is called once per frame
    void Update () {
       for (int x = 0; x < size*size-1; x++)
        {
            Debug.DrawLine(vertices[x], vertices[x + 1], Color.green);
        }

    }
}

Error failed setting triangles. some indices are referencing out of bounds vertices

the unity forums are to slow please help.

|| CPU Intel Core i7‑4790K 4.9 Ghz || Motherboard MSI Z97S SLI Krait Edition || RAM corsair vengeance pro 4x8gb 2400mhz || GPU msi msi twin frozr gtx 1080 8g sli x2 || Case nzxt phantom 410 || Cooling corsair h100i ||

Link to comment
https://linustechtips.com/topic/560275-unity-mesh-generation/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×