Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ChunkGenerator : MonoBehaviour
- {
- public GameObject dirtTile;
- public GameObject grassTile;
- public GameObject stoneTile;
- public Transform groundFolder;
- public Transform plantsFolder;
- public int width;
- public float heightMultiplier;
- public int heightAddition;
- public float smoothness;
- float seed;
- void Start()
- {
- Generate();
- seed = Random.Range(-10000f, 10000f);
- }
- public void Generate()
- {
- for(int i = 0; i < width; i++)
- {
- int h = Mathf.RoundToInt(Mathf.PerlinNoise(seed, i / smoothness) * heightMultiplier) + heightAddition;
- for(int j = 0; j < h; j++)
- {
- GameObject selectedTile;
- if(j < h - 4)
- {
- selectedTile = stoneTile;
- } else if (j < h - 1)
- {
- selectedTile = dirtTile;
- }
- else
- {
- selectedTile = grassTile;
- }
- Instantiate(selectedTile, new Vector3(i, j), Quaternion.identity);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement