At the moment I'm messing around with meshes just trying different things. The last few times I've been trying to make the mesh have two materials for different triangles but I can't figure out how it works in a script. With Blender, which I'm normally using to make meshes, it's easy: Assign a second material to some faces and Unity will import it correctly for you.
But how does it work with a mesh created by a script while the game is running?
- Set
subMeshCount
on the Mesh
object to the number of materials you need
- Call
SetTriangles
on the Mesh
object once for each material/submesh. Pass the appropriate material/submesh index as the second parameter
- Set
materials
on the MeshRenderer
to an array of materials
(You should only need one set of uv
s)
Nothing too difficult - you need to assign to both the uv and uv2 arrays in the mesh, then you need to assign an array of two materials to renderer.materials - don't try to modify renderer.materials one item at a time