- Home /
Question by
CaptainKirby · Apr 19, 2013 at 12:11 AM ·
vertexcolor
Change vertex color of mesh on z axis
Hi! I wonder if anyone can help me with making it so that the color of my vertex colors, darkens the further along the z axis it is, having 0 as the neutral point.
Right now i am trying with whatever much the documentation has given me from Mesh.colors
function Start () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var colors : Color[] = new Color[vertices.Length];
for (var i = 0; i < vertices.Length;i++)
colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].z);
mesh.colors = colors;
}
So what I get is the colors lerping between red and green(duh), but continously, red,green,red,green and so forth. What I want to have if going from one color to other color, and staying that color. So I presume that Colors.Lerp is doing it, but I am not certain how to do away with it... Any thoughts?
Thanks in advance!
Comment