- Home /
I want each face of an object to be a different color
So, I have an object I've modeled inside of Maya that have many faces. I want each face to be a different color (it's like a multicolor terrain). I have a certain set of colors (6) that I want to be the colors and then I want to write a script to randomly color each face of the object?? Is this possible and do you have any tips to achieving this?
There are several approaches depending on how efficient you need to be. The easiest (and lest efficient) is to assign a different material to each face in $$anonymous$$aya. Then you can just change any of the materials in the Renderer.materials array to change the color (or change the color of the existing material). Note this requires that the shader used in the materials have a _Color property.
You can use vertex colors as well. For sample code, please check robertbu's answer to this question.
Vertex colors is a more efficient solution if you have more than one of these models in the scene (allows for drawcall batching), but 1) you must identify the vertices that belong to each face and 2) you need a vertex shader (only a few of the shaders that come with Unity are vertex shaders), 3) modifying the colors array in the mesh is more complicated than just just changing the materials array. @ArkaneX - thanks for the suggestion.
I'd suggest making a texture with the 6 colors and modifying the UVs of each face to correspond to the desired texture pixel. It's similar to the vertex color suggestion but doesn't require special shaders.
@robertbu - you're welcome :)
@jyuhasz - I just recalled an article related to vertex colors I read a few months ago. One of the topics is coloring a terrain. Perhaps not exactly what you need, but I suggest reading anyway: http://www.alkemi-games.com/a-game-of-tricks-ii-vertex-color/
Answer by Awanonimik · Aug 05, 2017 at 01:05 AM
Don't know how helpful this is, but I'd recommend just colouring it normally (I personally have no idea how to do this, I'm a beginner too), and then randomly - or manually - rotating it inside the scene. It wouldn't be quite as random, but still pretty much so.
Postnote: as I finished writing this, I realized that this is a three-year-old question.