duck

Unity 3D Procedural Terrain - Step 1 - Sine Wave

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