How can I apply different colors to a cube face?
Can i apply a color through code also?
Creating a Q-bert type game clone.
Thanks for your help in getting me started with my first project.
Josh
How can I apply different colors to a cube face?
Can i apply a color through code also?
Creating a Q-bert type game clone.
Thanks for your help in getting me started with my first project.
Josh
Create the cube via code and then use vertex colors is your best option. If you want hard edges remember each face needs its own vertices. Once the cube is created its easy to then set a new colors array for the vertex colors each time you need a face to change color.
Or you make a mesh with a different sub-mesh for every face , a different material for each sub-mesh.
That way can can change the material / color for each face.
Like @shaderbytes mentioned, I would use vertex colours also.
Here are a few links on how to create a dynamic mesh in Unity:
(check out his other tutorials, such as ‘Maze’. A lot of good info in there.)
Thanks guys
I would not do that since that means 6 draw calls + when you have multiple cubes on stage and need to change colors it means you have to create a new material each time. If you had a mere 20 cubes you would end up with 120 draw calls. With vertex colors you can use one material for all the cubes with every face a different color and have only 1 draw call.
What if you had 6 submeshes all sharing the same vertex color material. At least now you can access a specific face quick and easy, then modify it’s four vertices’ color array. No extra draw calls. But then again, a cube only has 24 unique vertices, and just reading, modifying the correct 4, and then writing all 24 back each time may be tidier.
I would create a new class (or two) to handle keeping track of this for you. The ‘cube’ class would contain an array of 6 ‘face’ class instances which store each face’s vertices, normals, colors, etc. Then have a ‘build’ method that assembles a cube mesh based on the 6 face’s data.