Hey Guys.
I’m currently trying to create Marching Squares in Unity. For that purpose, I want to edit a Plane as such, that it becomes triangular (at least in my example here, in the full code there are more shapes possible).
Here is the part of the script:
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
GameObject.Destroy(plane.GetComponent<MeshCollider>());
mesh = new Mesh();
plane.GetComponent<MeshFilter>().mesh = mesh;
plane.transform.SetParent(parent);
Vector3[] vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(0.5f, 0, 0), new Vector3(0, 0, 0.5f) };
int[] triangles = new int[] { 0, 1, 2 };
Vector3[] normals = new Vector3[] { Vector3.down, Vector3.down, Vector3.down };
Vector2[] uv = new Vector2[] { new Vector2(0, 0), new Vector2(0.5f, 0), new Vector2(0, 0.5f) };
mesh.name = "Procedural Marching Squares";
mesh.Clear();
mesh.vertices = vertices;
mesh.normals = normals;
mesh.uv = uv;
mesh.triangles = triangles;
plane.GetComponent<Renderer>().material = groud_material;
Note: most of the not-defined variables are just global variables defined in the inspector
As soon as I run the code, a plane appears in the hierarchy but is not visible on the screen. I can select it and can see the orange outline, but it doesn’t correctly render as an Object. Also, no wire-mesh is visible.
I tried running an example for creating a cube I found online which worked flawlessly. I’m trying to find the mistake for about an hour now, but I can’t get it to work.
~Okaghana