i try to make a chunksystem for my game, to place, remove and color cubes.
But my problem is that i can't color each side from a normal cube. I tried to make a mesh but i don't find out how to color spezefic areas.
Sorry for my bad english, i'm german^^
So i try that the player can place a cube on a 16*16 chunk. When the cube is placed the player should be able to color each side. like the front red, the back green etc.
I tried to make a cube out of planes, but that a way to much objects and couses into lags.
Maybe u have an idea? Please i try it now for over 3 days^^
My code for now: (I Already have a cube place system etc. This is a new try)
The basic idea is to build each face with its own vertices. This increases the vertex count, but not the triangle count. Each face has it own set of vertices, then you can color the face by either by using a Vertex Colored shader and changing the vertex colors, or by using a texture atlas and changing the UV coordinates to a different point in the atlas.
There are three scripts below. The first is a very simple vertex shader, the second creates a cube mesh and processes the hit on a triangle in that mesh. The third processes the mouse click and passed the triangle index. If you setup all three correctly, you will be able to click on a cube face to change it to random color.
This is the simplest vertex color shader I know. If you Google "Unity3d Vertex Colored Shader" you will find others with more features.
The following code builds a cube. The mesh does not have to be a cube to work. The more important ingredient is that each face you want to color has its own set of vertices. Attach the script to an empty game object that has these three components: a) MeshCollider b) Renderer, c) MeshFilter.
Note the statement "int iStart = mesh.triangles[iTriangle*3];" works to find the beginning index of the four vertices (or four colors matched to the indices) because the two trangles both use the first of the four points as the start of each rectangle.
And here is a script that does the Raycasting and triggers the change in color. Attach it to an empty game object.
answered Feb 02 '13 at 05:43 AM