Material for each Submesh in script

I have a square as Gameobject and i add four triangles to the Mesh:
Also i have a Material Array.

62694-mesh.png

How can i create four submeshes with the four triangles and add each a different Material with the script.
Please give me a code example.

It goes like this:

You know that your mesh has an int mesh.triangles that contains vertex indices.
Now, to use different materials for different triangles, you have to create a new List(int) or int for each seperate submesh, and fill them with the appropriate vertex indices.
You then have to set the mesh’s subMeshCount and use Mesh.SetTriangles. Now you only have to pass a material to the renderer which contains the correct number of materials.

Code examples are included in the linked Scripting API pages.