Dynamically generating textures for a mesh,Generating a texture for a dynamically generated mesh

Hello. I have some generated terrain which consists of highly irregular triangles. I want to colour the mesh based on the height of each triangle, but I can’t find any information on how to colour each triangle with a single colour using a material. The only idea I have is to generate a texture dynamically which will contain the necessary colours, but the problem with that is that AFAIK since the UV coordinates of the mesh are all at the positions of vertexes, the colour will be interpolated between them anyway. How can I ensure that each triangle is one solid colour?

Unity Mesh supports vertex color. Maybe you can find a shader/material that display vertex color, and add vertex color in your generated terrain.