Code: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeshControl : MonoBehaviour { private List<Vector3> grid; private Material[] materials; [SerializeField] private Object node; private Vector3[] vertices; private Vector3[] normals; private int[] triangles; private Mesh mesh; private MeshFilter mf; private int i; void Start() { grid = new List<Vector3>(); AddMesh(new Vector3(0, 0, 0), new Vector3(3, 1, 3), new Vector3(3, 0, 4)); LoadMeshs(); } void Update() { } void BuildMesh(Vector3 vec1, Vector3 vec2, Vector3 vec3, bool invert) { int a = i - 1; vertices[0 + a] = vec1; vertices[1 + a] = vec2; vertices[2 + a] = vec3; normals[0 + a] = new Vector3(Mathf.Sin(GetDir(new Vector2(vec1.x - vec2.x, vec1.z - vec2.z))), Mathf.Sin(GetDir(new Vector2(vec1.x - vec2.x, vec1.y - vec2.y))), Mathf.Cos(GetDir(new Vector2(vec1.x - vec2.x, vec1.z - vec2.z)))); normals[1 + a] = new Vector3(Mathf.Sin(GetDir(new Vector2(vec1.x - vec2.x, vec1.z - vec2.z))), Mathf.Sin(GetDir(new Vector2(vec1.x - vec2.x, vec1.y - vec2.y))), Mathf.Cos(GetDir(new Vector2(vec1.x - vec2.x, vec1.z - vec2.z)))); normals[2 + a] = new Vector3(Mathf.Sin(GetDir(new Vector2(vec1.x - vec2.x, vec1.z - vec2.z))), Mathf.Sin(GetDir(new Vector2(vec1.x - vec2.x, vec1.y - vec2.y))), Mathf.Cos(GetDir(new Vector2(vec1.x - vec2.x, vec1.z - vec2.z)))); triangles[0 + a] = 0 + a; triangles[1 + a] = 1 + a; triangles[2 + a] = 2 + a; mesh.vertices = vertices; mesh.normals = normals; mesh.triangles = triangles; mf = GetComponent<MeshFilter>(); mf.mesh = mesh; Instantiate(node, vec1, transform.rotation); Instantiate(node, vec2, transform.rotation); Instantiate(node, vec3, transform.rotation); } float GetDir(Vector2 pos) { if (pos.y < 0) { return (Mathf.Atan(pos.x / pos.y) + 180f); } else { return (Mathf.Atan(pos.x / pos.y) + 0f); } } void AddMesh(Vector3 vec1, Vector3 vec2, Vector3 vec3) { grid.Add(vec1); grid.Add(vec2); grid.Add(vec3); } void LoadMeshs() { mesh = new Mesh(); vertices = new Vector3[grid.Count]; normals = new Vector3[grid.Count]; triangles = new int[grid.Count]; i = 0; for (int a = 0; a <= grid.Count / 3; a++) { i++; if (i - 1 < grid.Count / 3) { BuildMesh(grid[i*3-3], grid[i*3-2], grid[i*3-1], false); } } } void ClearAll() { GetComponent<MeshFilter>().mesh.Clear(false); } } This code will work but if I add another AddMesh(new Vector3(0, 0, 0), new Vector3(3, 1, 3), new Vector3(3, 0, 4)); it will not render them at all.
Your AddMesh method does nothing but add three elements to a list. You actually need to update the mesh afterwards.
Would've been useful to mention that then. Can't read minds, mate. Are the normals facing the right way? You should really be debugging this on your own rather than posting a forum thread with every single issue you hit.