• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by jyuhasz · Apr 10, 2014 at 06:57 PM · materialcolormaya

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?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Apr 10, 2014 at 07:08 PM 0
Share

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.

avatar image ArkaneX · Apr 11, 2014 at 03:53 PM 1
Share

You can use vertex colors as well. For sample code, please check robertbu's answer to this question.

avatar image robertbu · Apr 11, 2014 at 04:00 PM 1
Share

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.

avatar image Eric5h5 · Apr 11, 2014 at 04:33 PM 2
Share

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.

avatar image ArkaneX · Apr 11, 2014 at 04:36 PM 0
Share

@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/

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Is there a technique to change the color of Line Renderer between two points? 3 Answers

Cant change GO material with multipli material 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges