Help with Vertex Colors

I’m trying to color a mesh using vertex colors and I can’t get it to work. I’m using the Mobile/VertexLit shader. Here’s my code:

	void Start () {
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		Color[] colors = new Color[mesh.vertexCount];
		for (int i = 0; i < mesh.vertexCount; i++)
		{
		colors *= Color.black;*
  •  }*
    
  •  mesh.colors = colors;*
    
  • }*
    What am I doing wrong?

That's hard to answer. What is going wrong? Are you crashing? Are the visuals not what you expected? Do you have a shader that is using the vertex color channel?

–

Try the Mobile/Vertex Colored shader.

–

It just doesn't color the object. I don't seem to have the "Mobile/Vertex Colored" shader. Maybe I'm doing this wrong. I created a material and set the shader to Mobile/VertexLit. Then I added that material to my model. Am I supposed to set up the shader some other way?

–

1 Answer

1

You are doing it right. I tested your code with Mobile/VertexLit and it failed. I tested it with Mobile/Vertex Colored and it worked fine. Do Assets > Import Package > Standard Assets (Mobile) to get the Vertex Colored shader.

Here is a link to another one that should work as a test. You want the first one on the page:

http://wiki.unity3d.com/index.php/VertexColorUnlit

That worked. Thanks!

–