- Home /
Question by
Evan-Thomas · Oct 20, 2020 at 11:54 AM ·
meshlightingprocedural generationterrain generationprocedural-terrain
No light on a script generated mesh.
I have created procedural terrain generator with meshes. The problem is that there is no light reflecting, so the object is in darkness. I do not know why this is occurring. Below is my Code. Thanks in advance
private void TerrainGenTri() {
Mesh mesh = new Mesh();
int counter = 0;
for(int y = 0; y < terrainSize.y - 1; y ++)
{
for (int x = 0; x < terrainSize.x - 1 ; x ++) {
temp[counter] = new Vector3(x, terrainHeight[x, y], y);
counter += 1;
temp[counter] = new Vector3(x, terrainHeight[x, y + 1], y + 1);
counter += 1;
temp[counter] = new Vector3(x + 1, terrainHeight[x + 1, y], y);
counter += 1;
temp[counter] = new Vector3(x + 1, terrainHeight[x + 1, y], y);
counter += 1;
temp[counter] = new Vector3(x, terrainHeight[x, y + 1], y + 1);
counter += 1;
temp[counter] = new Vector3(x + 1, terrainHeight[x + 1, y + 1], y + 1);
counter += 1;
}
}
gameObject.AddComponent<MeshFilter>();
GetComponent<MeshFilter>().mesh = mesh;
mesh.vertices = temp;
int[] verticiesList = new int[counter];
for (int number = 0; number < counter; number++) {
verticiesList[number] = number;
}
mesh.triangles = verticiesList;
gameObject.AddComponent<MeshRenderer>();
gameObject.AddComponent<MeshCollider>();
GetComponent<Renderer>().material = mat;
}
Comment
Your answer
Follow this Question
Related Questions
How can I represent different biomes on a Terrain object? 0 Answers
2D topdown generating stairs (access) to generated hill 0 Answers
How Do I Properly Generate Biomes In Infinite Terrain? 1 Answer
Strange point light on generated mesh 1 Answer
Mesh does not have UVs suitable for Lightmapping - Lighting Issue 2 Answers