Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void randomTerrain(Edit edit, Terrain terrain)
- {
- int xResolution = terrain.terrainData.heightmapWidth;
- int zResolution = terrain.terrainData.heightmapHeight;
- height = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight);
- switch(edit)
- {
- case Edit.cosinoise:
- for (int z = 0; z < zResolution; z++)
- {
- for (int x = 0; x < xResolution; x++)
- {
- float xSin = Mathf.Cos(x);
- float zSin = -Mathf.Sin(z);
- height[x, z] = (xSin - zSin) / 100;
- }
- }
- break;
- case Edit.perlin:
- for (int z = 0; z < zResolution; z++)
- {
- for (int x = 0; x < xResolution; x++)
- {
- height[x,z] = Mathf.PerlinNoise(((float)x / (float)terrain.terrainData.heightmapWidth) * noisesize, ((float)z / (float)terrain.terrainData.heightmapHeight) * noisesize) / 10.0f;
- }
- }
- break;
- }
- terrain.terrainData.SetHeights(0, 0, height);
- for (int z = 0; z < zResolution; z++)
- {
- for (int x = 0; x < xResolution; x++)
- {
- chunk1.setTile(x, z, new Tile((int)height[x, z], 0));
- }
- }
- }
- public enum Edit
- {
- perlin,
- cosinoise
- }
Advertisement
Add Comment
Please, Sign In to add comment