Vertex coloring isn't working

So, I’m making a custom mesh directly from scripting, setting up the vertices, triangles, normals and UVs, and now also trying to change the vertices colors (Vertex colors).

However, even tho I don’t have any errors when I run the script, no results shows up. The mesh aren’t colored or anything, but the colors ARE getting actually getting inserted to the mesh.

This is my code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RoomCreator : MonoBehaviour {

	private List<Vector3> Mesh_Vertices = new List<Vector3>();
	private List<Vector2> Mesh_Uvs = new List<Vector2>();
	private List<int> Mesh_Triangles = new List<int>();

	private MeshFilter meshFilter;

	void Start() {
		meshFilter = GetComponent<MeshFilter>();

		CreateRoom();
	}

	private void CreateRoom() {
		meshFilter.mesh = CreateMesh();
	}

	private Mesh CreateMesh() {
		Mesh m = new Mesh();
		m.name = gameObject.name + "_Mesh";
		
		CreateFace(new Vector3(0,0,0), 10,1,0);
		CreateFace(new Vector3(10,0,0), 0,1,10);

		m.vertices = Mesh_Vertices.ToArray();
		m.triangles = Mesh_Triangles.ToArray();
		m.uv = Mesh_Uvs.ToArray();
		m.RecalculateNormals();

		print("Vertices: " + Mesh_Vertices.Count); // Vertices: 8
		print("Triangles: " + Mesh_Triangles.Count); // Triangles: 12

		Color[] colors = ColorizeFaces(m.vertices, m.triangles);
		m.colors = colors;

		print("Colors: " + m.colors.Length); // Colors: 8

		return m;
	}
	
	private Color[] ColorizeFaces(Vector3[] vertices, int[] triangles) {
		Color[] colors = new Color[vertices.Length];
		Color triColor = getRandomColor();

		for (int i = 0; i < triangles.Length; i++)
		{
			int vertIndex = triangles*;*
  •  	if (i % 3 == 0)*
    
  •  		triColor = getRandomColor();*
    
  •  	colors[vertIndex] = triColor;*
    
  •  }*
    
  •  return colors;*
    
  • }*

  • private Color getRandomColor()*

  • {*

  •  float red = Random.Range(0.0f, 1.0f);*
    
  •  float green = Random.Range(0.0f, 1.0f);*
    
  •  float blue = Random.Range(0.0f, 1.0f);*
    
  •  return new Color(red, green, blue);*
    
  • }*

  • private void CreateFace(Vector3 position,int width, int height, int depth) {*

  •  Mesh_Vertices.Add(new Vector3(position.x, position.y, position.z));*
    
  •  Mesh_Vertices.Add(new Vector3(position.x+width, position.y, position.z+depth));*
    
  •  Mesh_Vertices.Add(new Vector3(position.x, position.y+height, position.z));*
    
  •  Mesh_Vertices.Add(new Vector3(position.x+width, position.y+height, position.z+depth));*
    
  •  int a = Mesh_Vertices.Count-1;*
    
  •  int b = a-1;*
    
  •  int c = a-2;*
    
  •  int d = a-3;*
    
  •  Mesh_Triangles.Add(a);*
    
  •  Mesh_Triangles.Add(b);*
    
  •  Mesh_Triangles.Add(d);*
    
  •  Mesh_Triangles.Add(d);*
    
  •  Mesh_Triangles.Add(c);*
    
  •  Mesh_Triangles.Add(a);*
    
  •  Mesh_Uvs.Add(new Vector2(0,0));*
    
  •  Mesh_Uvs.Add(new Vector2(1,0));*
    
  •  Mesh_Uvs.Add(new Vector2(0,1));*
    
  •  Mesh_Uvs.Add(new Vector2(1,1));*
    
  • }*
    }

You need to use a shader that utilizes vertex colors; most of the built-in shaders don’t.

Use a Shader like this:

Shader "Custom/Vertex Colored Lighted" {
Properties {
}
    SubShader {
            Pass {
                    ColorMaterial AmbientAndDiffuse
                    Lighting On
            }
    } 
}