- Home /
Mesh with two materials made by script
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?
Answer by jovalent · Dec 31, 2017 at 08:18 AM
Set
subMeshCount
on theMesh
object to the number of materials you needCall
SetTriangles
on theMesh
object once for each material/submesh. Pass the appropriate material/submesh index as the second parameterSet
materials
on theMeshRenderer
to an array of materials
(You should only need one set of uv
s)
Exactly, up voted and accepted since this is such an old question.
@Bunny83 I'm working on Cut $$anonymous$$esh and have some confusing issues. Can you please give me an email so that I can exchange some of the issues. Or email to hdt.nl90@gmail.com
Answer by Mike 3 · May 18, 2010 at 01:55 PM
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
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Is it possible to save runtime generated mesh as a texture ? 1 Answer
How to cut meshes ? 0 Answers
.Obj Exporter with .Mtl 0 Answers