Hi, I’m trying to vertex color every triangle on mesh with random color, but I’m getting this:
[31148-wrong.jpg*_|31148]
but I’m want to get this:
[31149-correct.jpg*_|31149]
The red triangle is always one-colored and other ones on mesh aren’t.
using UnityEngine;
using System.Collections;
public void VertsColor(GameObject gameObject)
{
Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
int[] triangles = mesh.triangles;
Vector3[] vertices = mesh.vertices;
Vector3[] verticesModified = new Vector3[triangles.Length];
int[] trianglesModified = new int[triangles.Length];
Color32 currentColor = new Color32();
Color32[] colors = new Color32[triangles.Length];
for (int i = 0; i < trianglesModified.Length; i++) {
// Makes every vertex unique
verticesModified _= vertices[triangles*];*_
_ trianglesModified = i;
* // Every third vertex randomly chooses new color*
colors[triangles*] = currentColor;
if(triangles % 3 == 0)
currentColor = new Color(
Random.Range (0.0f, 1.0f),
Random.Range (0.0f, 1.0f),
Random.Range (0.0f, 1.0f),
1.0f);
}
// Applyes changes to mesh*
* mesh.vertices = verticesModified;
mesh.triangles = trianglesModified;
mesh.colors32 = colors;
}
Thanks for your help!
_*