- Home /
Change triangle color on mesh
Hi, i have mesh with two triangles
and i want to change triangle nuber 2 to blue color by clicking.
Like this: Can somebody help me?
Answer by Gmotagi · Nov 20, 2016 at 05:29 PM
When you create the mesh also create an array of Color[] with the same number of values as vertices. e.g.
var colours = new Color[numVerticies];
Then for each colour in the array where the array index matches the vertex array index , set the colour.
If bottom left (BL) is index 0, top left (TL) = 1, top right (TR) =2, bottom right(BR) = 3 (in both vertex and color arrays)
colours[0] = new Color(0,0.1); // Note values are 0..1 not 0..255 colours[2] = new Color(0,0.1); colours[3] = new Color(0,0.1);
then set them on the mesh mesh.colors = colours;
HOWEVER - because both triangles share two vertex in common (BL & TR) those vertexes will will share the same color, and the top left triangle will have a blended colour. To correct this you need both triangles to each have three vertexes then you can have the BL & TR vertex with a separate colour.
In this case array size will be 6
Answer by MrKagouris · Nov 20, 2016 at 05:18 PM
You could create a second plane in the same spot and tilt both slightly so half of one is triangle 1 and half of the other is triangle 2.
Your answer
![](https://koobas.hobune.stream/wayback/20220612101000im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to colorize a face of a Mesh 0 Answers
Multiple Cars not working 1 Answer