Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class LandscapeGenerator : MonoBehaviour
  5. {
  6. public int width = 32;
  7. public int depth = 32;
  8. public int heightScale = 20;
  9. public float detailScale = 25f;
  10.  
  11. public bool autoUpdate;
  12.  
  13. public GameObject grassBlock;
  14.  
  15. public void GenerateLandscape()
  16. {
  17. string holderName = "Generated Landscape";
  18. if (transform.FindChild(holderName))
  19. DestroyImmediate(transform.FindChild(holderName).gameObject);
  20.  
  21. Transform landscapeHolder = new GameObject(holderName).transform;
  22. landscapeHolder.parent = transform;
  23.  
  24. for (int z = 0; z < depth; z++)
  25. for (int x = 0; x < width; x++)
  26. {
  27. int y = (int)(Mathf.PerlinNoise(x / detailScale, z / detailScale) * heightScale);
  28. Vector3 blockPosition = new Vector3(x, y, z);
  29.  
  30. GameObject newBlock = Instantiate(grassBlock, blockPosition, Quaternion.identity) as GameObject;
  31. newBlock.transform.parent = landscapeHolder;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement