Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class LandscapeGenerator : MonoBehaviour
- {
- public int width = 32;
- public int depth = 32;
- public int heightScale = 20;
- public float detailScale = 25f;
- public bool autoUpdate;
- public GameObject grassBlock;
- public void GenerateLandscape()
- {
- string holderName = "Generated Landscape";
- if (transform.FindChild(holderName))
- DestroyImmediate(transform.FindChild(holderName).gameObject);
- Transform landscapeHolder = new GameObject(holderName).transform;
- landscapeHolder.parent = transform;
- for (int z = 0; z < depth; z++)
- for (int x = 0; x < width; x++)
- {
- int y = (int)(Mathf.PerlinNoise(x / detailScale, z / detailScale) * heightScale);
- Vector3 blockPosition = new Vector3(x, y, z);
- GameObject newBlock = Instantiate(grassBlock, blockPosition, Quaternion.identity) as GameObject;
- newBlock.transform.parent = landscapeHolder;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement