How to change vertex color from script?

How do I change vertex color in runtime?

Basically, I want to plot a 2d scalar field by painting a grayscale map on the vertices of a plane.

Change the colors array of the mesh with Mesh.colors

Have a look in the Scripting documentation and look for the class called “Mesh”. It has a property called “colors” which contains a Color object for every vertex in the mesh. Manipulating this array will set the vertex color at runtime.