public void ConstructMesh() { Vector3[] vertices = new Vector3[resolution * resolution]; //List of vertex int[] triangles = new int[(resolution - 1) * (resolution - 1) * 6]; //Number of triangles int triIndex = 0; enemyIndex = 0; otherIndex = 0; otherWRIndex = 0; circles = new GameObject[vertices.Length]; enemies = new GameObject[enemyMaxNum]; others = new GameObject[othersMaxNum]; othersWR = new GameObject[othersWRMaxNum]; enemyParent = new GameObject[groupNum]; otherParent = new GameObject[groupNum]; otherWRParent = new GameObject[groupNum]; for (int i = 0; i < groupNum; i++) { enemyParent[i] = new GameObject("enemyParent"); enemyParent[i].transform.parent = mountainTransform.transform; enemyParent[i].transform.position = new Vector3(0, 0, 0); enemyParent[i].AddComponent <ContentSection>(); enemyParent[i].GetComponent <ContentSection>().isEnemy = true; otherParent[i] = new GameObject("otherParent"); otherParent[i].transform.parent = mountainTransform.transform; otherParent[i].transform.position = new Vector3(0, 0, 0); otherParent[i].AddComponent <ContentSection>(); otherParent[i].GetComponent <ContentSection>().isEnemy = false; otherWRParent[i] = new GameObject("otherWRParent"); otherWRParent[i].transform.parent = mountainTransform.transform; otherWRParent[i].transform.position = new Vector3(0, 0, 0); otherWRParent[i].AddComponent <ContentSection>(); otherWRParent[i].GetComponent <ContentSection>().isEnemy = false; if (player != null) { enemyParent[i].GetComponent <ContentSection>().player = player; otherParent[i].GetComponent <ContentSection>().player = player; otherWRParent[i].GetComponent <ContentSection>().player = player; } } for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { int i = x + y * resolution; Vector2 percent = new Vector2(x, y) / (resolution - 1); //What percent of the generation is complete Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; //Current position on the face Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; vertices[i] = shapeGenerator.CalculatePointOnMountain(pointOnUnitSphere, seed, i);//add the points to array with noise applied //Random.seed = System.DateTime.Now.Millisecond; if (vertices[i].y > 3) { GenerateContent(vertices[i], i); } if (x != resolution - 1 && y != resolution - 1)//Not at the edge //Triangle1 { triangles[triIndex] = i; triangles[triIndex + 1] = i + resolution + 1; triangles[triIndex + 2] = i + resolution; //Triangle2 triangles[triIndex + 3] = i; triangles[triIndex + 4] = i + 1; triangles[triIndex + 5] = i + resolution + 1; triIndex += 6; } } } //Adding vertices and triangles to the mesh mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); //Set peak spawn location if (localUp == Vector3.up) { peakPoint = vertices[shapeGenerator.elevationMinMax.Index] + mountainTransform.position;//Assign peak vertex } //Set mesh if (meshCollider != null) { meshCollider.sharedMesh = mesh; } circleParent = new GameObject[8]; //Set circleParent for (int i = 0; i < 8; i++) { circleParent[i] = new GameObject("circleParent"); circleParent[i].transform.parent = mountainTransform.transform; circleParent[i].transform.position = new Vector3(0, 0, 0); circleParent[i].AddComponent <ContentSection>(); circleParent[i].GetComponent <ContentSection>().isCircle = true; if (player != null) { circleParent[i].GetComponent <ContentSection>().player = player; } } for (int i = 0; i < vertices.Length; i++) { if (vertices[i].y > -0.1) { if (i <= (vertices.Length / 8)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[0].transform); } else if (i <= ((vertices.Length / 8) * 2)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[1].transform); } else if (i <= ((vertices.Length / 8) * 3)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[2].transform); } else if (i <= ((vertices.Length / 8) * 4)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[3].transform); } else if (i <= ((vertices.Length / 8) * 5)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[4].transform); } else if (i <= ((vertices.Length / 8) * 6)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[5].transform); } else if (i <= ((vertices.Length / 8) * 7)) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[6].transform); } else if (i <= vertices.Length) { GenerateCircle(vertices[i] + mountainTransform.position, i, circleParent[7].transform); } } } }