c# – Submesh not appearing with different materials Unity2D

c# – Submesh not appearing with different materials Unity2D

Your outline mesh is not correctly constructed.

Your outline mesh is, in fact, a circle, not a ring.

Because of this, when the entire thing is rendered, the outline and the inner portion are in the same place. If you were to move the camera around I suspect youd see some Z-Fighting.

To correctly render your object, you need to actually create a ring for your outline.

Secondly, youre smashing both submeshes together into a single triangles array:

List<int> trianglesList = new List<int> { };
List<int> OLtrianglesList = new List<int> { };
for (int i = 0; i < (n - 2); i++)
{
    trianglesList.Add(0);
    trianglesList.Add(i + 1);
    trianglesList.Add(i + 2);
}
for (int i = 0; i < (n - 2); i++)
{
    trianglesList.Add(n);
    trianglesList.Add(i + n + 1);
    trianglesList.Add(i + n + 2);
}

Notice that OLtrianglesList is not used!

It probably doesnt help that you use a single list for both sets of verticies, either:

for (int i = 0; i < n; i++)
{
    x = radius * Mathf.Sin((2 * Mathf.PI * i) / n);
    y = radius * Mathf.Cos((2 * Mathf.PI * i) / n);
    verticesList.Add(new Vector3(x, y, 0f));
}
for (int i = 0; i < n; i++)
{
    x = (radius + OLwidth) * Mathf.Sin((2 * Mathf.PI * i) / n);
    y = (radius + OLwidth) * Mathf.Cos((2 * Mathf.PI * i) / n);
    verticesList.Add(new Vector3(x, y, 0f));
}

c# – Submesh not appearing with different materials Unity2D

Leave a Reply

Your email address will not be published. Required fields are marked *