- Home /
Question by
HOS · Oct 29, 2013 at 01:38 PM ·
mesh verticesmesh color
Graphics.DrawMesh - cannot set mesh color
I'm trying to draw rectangular meshes (two triangles) with custom colors that fade from one corner to the other. The rectangles are showing in the correct position, but they are not showing any colors at all. They are always black no matter what colors I assign. Here is what I've done. Can anyone see why the meshes are not showing any colors?
void Update()
{
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[ 4 ];
for( int i=0; i<4; i++ )
{
vertices[ i ].x = posX[ i ];
vertices[ i ].y = posY[ i ];
vertices[ i ].z = 0.2f;
}
mesh.vertices = vertices;
int[] triangles = new int[6]
{
0, 3, 1,
3, 2, 1
};
mesh.triangles = triangles;
Color[] colors = new Color[ 4 ];
for( int i=0; i<4; i++ )
{
colors[ i ] = Color.Lerp( Color.Green , Color.Red , vertices[ i ].y;
}
mesh.colors = colors;
Graphics.DrawMesh( mesh , Matrix4x4.identity , m_CoverMaterial , 0 );
}
I'm using a material that uses Mobile/VertexLit. I have tried assigning a texture to the material but that makes no difference, still just black rectangles...
Comment