At the start of my game i want to create a chunk of terrain:
void StartChunk ()
{
refPoints = new float[chunkLength+1];
blocks = new GameObject[chunkLength];
for (int i = 0; i < refPoints.Length; i++)
{
refPoints *= Random.Range (y1Min, y1Max);*
-
}* -
for (int i = 0; i < blocks.Length; i++)* -
{* -
GenerateMeshes (i);* -
}* -
} *
The methodGenerateMesheslooks like this:
void GenerateMeshes (int i) -
{ *
_ blocks = Instantiate (block, new Vector3 (0, 0, 0), transform.rotation) as GameObject;_
_ MeshFilter mf = blocks .GetComponent ();
* Mesh mesh = new Mesh ();
mf.mesh = mesh;*_
* //Vertices*
* vertices = new Vector3[4] {*
* new Vector3 (i-9, -6,0),*
* new Vector3 (i-8, -6,0),*
_ new Vector3 (i-9, refPoints*,0),
new Vector3 (i-8, refPoints[i+1],0),
};*_
* //Triangles*
* int[] tri = new int[6];*
* tri [0] = 0;*
* tri [1] = 1;*
* tri [2] = 2;*
* tri [3] = 2;*
* tri [4] = 3;*
* tri [5] = 1;*
* //UV’s*
* Vector2[] uv = new Vector2[4];*
* uv [0] = new Vector2 (0, 0);*
* uv [1] = new Vector2 (1, 0);*
* uv [2] = new Vector2 (0, 1);*
* uv [3] = new Vector2 (1, 1);*
* mesh.vertices = vertices;*
* mesh.triangles = tri;*
* mesh.uv = uv;*
* }*
When the method StartChunk is called i get this result:
[74893-fek.png|74893]
But what i want to achieve is something like this:
[74894-fek2.png*|74894]*
*
*
I think i have to modify my GenerateMeshes method but i really cant figure out what to do, any help is appreciated.
Thanks.
Not sure without testing it, but the order of the vertices in your tri defines the direction of the normals, so try this one for the first triangle: tri [0] = 0; tri [1] = 2; tri [2] = 1;
– ScaniX