Guest User

Untitled

a guest
Nov 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Perlin : MonoBehaviour {
  6.  
  7. // Use this for initialization
  8. void Start () {
  9.  
  10. GameObject obj = GameObject.Find("Terrain");
  11.  
  12. if (obj.GetComponent<Terrain>())
  13. {
  14. Terrain terrain = obj.GetComponent<Terrain>();
  15. float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
  16.  
  17. float tileSize = 10.0f;
  18. print(terrain.terrainData.heightmapWidth);
  19. print(terrain.terrainData.heightmapHeight);
  20. for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
  21. {
  22. for (int k = 0; k < terrain.terrainData.heightmapHeight; k++)
  23. {
  24. float x = ((float)i / (float)terrain.terrainData.heightmapWidth) * tileSize;
  25. float y = ((float)k / (float)terrain.terrainData.heightmapHeight) * tileSize;
  26. // print(x);
  27. // print(y);
  28. float h = (PerlinNoise.getHeight(x, y) + 1) / 10.0f;
  29.  
  30. heights[i, k] = h;
  31. }
  32. }
  33.  
  34. terrain.terrainData.SetHeights(0, 0, heights);
  35. }
  36.  
  37.  
  38. }
  39.  
  40. // Update is called once per frame
  41. void Update () {
  42.  
  43. }
  44. }
Add Comment
Please, Sign In to add comment