Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ChunkGenerator : MonoBehaviour
  5. {
  6.     public GameObject dirtTile;
  7.     public GameObject grassTile;
  8.     public GameObject stoneTile;
  9.  
  10.     public Transform groundFolder;
  11.     public Transform plantsFolder;
  12.  
  13.     public int width;
  14.     public float heightMultiplier;
  15.     public int heightAddition;
  16.  
  17.     public float smoothness;
  18.  
  19.     float seed;
  20.  
  21.     void Start()
  22.     {
  23.         Generate();
  24.         seed = Random.Range(-10000f, 10000f);
  25.     }
  26.  
  27.     public void Generate()
  28.     {
  29.         for(int i = 0; i < width; i++)
  30.         {
  31.             int h = Mathf.RoundToInt(Mathf.PerlinNoise(seed, i / smoothness) * heightMultiplier) + heightAddition;
  32.             for(int j = 0; j < h; j++)
  33.             {
  34.                 GameObject selectedTile;
  35.                 if(j < h - 4)
  36.                 {
  37.                     selectedTile = stoneTile;
  38.                 } else if (j < h - 1)
  39.                 {
  40.                     selectedTile = dirtTile;
  41.                 }
  42.                 else
  43.                 {
  44.                     selectedTile = grassTile;
  45.                 }
  46.                 Instantiate(selectedTile, new Vector3(i, j), Quaternion.identity);
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement