- Home /
How to change the color of a mesh?
Mesh m = new Mesh();
m.vertices = poss;
m.uv = uvs;
m.triangles = new int[] { 0, 1, 2, 1, 2, 3 };
m.colors = new Color[] {natural, natural, natural, natural };
m.RecalculateNormals();
The mesh is then added to a GameObject with the components MeshRenderer, MeshFilter and MeshCollider.
The mesh is generated in the position and form I want, but the problem is the color: It's supposed to be green, but it becomes the default pink color.
I have also tried renderer.material.color = Color.green;
, but then only 1 triangle (?, one of the two diagonals) of the square is colored. How do I color the other one?
I understand that the reason my vertex colors aren't working is because of my shader: How do I change the Shader?
Why didn't my second try with coloring the material work?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613105433im_/https://answers.unity.com/themes/thub/images/avi.jpg)