duck

Unity 3D Procedural Terrain - Step 3 - Perlin Noise 1 Layer

Mar 1st, 2013
1,389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TerrainNoise : MonoBehaviour {
  5.  
  6.     // Use this for initialization
  7.     void Start () {
  8.        
  9.         Terrain terrain = GetComponent<Terrain>(); 
  10.        
  11.         TerrainData data = terrain.terrainData;
  12.        
  13.         float[,] heights = new float[ data.heightmapWidth, data.heightmapHeight] ;
  14.            
  15.         for( int x=0; x< data.heightmapWidth; ++x)
  16.         {
  17.             for( int z=0; z< data.heightmapHeight; ++z)
  18.             {
  19.                
  20.                 heights[x,z] = Mathf.PerlinNoise(x*0.01f, z*0.01f) * 1f  ;
  21.                
  22.             }
  23.         }
  24.        
  25.         data.SetHeights(0, 0, heights);
  26.        
  27.     }
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment