Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TerrainStuff : MonoBehaviour {
- Terrain terrain;
- // Use this for initialization
- // frequencies
- float f1,f2;
- // heights
- float h1,h2;
- void OnGUI()
- {
- GUILayout.Label("Frequency 1: "+f1);
- f1 = GUILayout.HorizontalSlider(f1, .001f, 1f);
- GUILayout.Label("Height 1: "+h1);
- h1 = GUILayout.HorizontalSlider(h1, .01f, 1f);
- GUILayout.Label("Frequency 2: "+f2);
- f2 = GUILayout.HorizontalSlider(f2, .001f, 1f);
- GUILayout.Label("Height 2: "+h2);
- h2 = GUILayout.HorizontalSlider(h2, .01f, 1f);
- }
- void SetTerrainHeights () {
- terrain = GetComponent<Terrain>();
- TerrainData data = terrain.terrainData;
- float[,] heights = data.GetHeights(0, 0, data.heightmapWidth, data.heightmapHeight);
- for( int x=0; x<512; ++x)
- {
- for( int z=0; z<512; ++z)
- {
- // resuts
- float r1 = Mathf.Sin ( x*f1 ) * h1 + h1;
- float r2 = Mathf.Sin ( z*f2 ) * h2 + h2;
- heights[x,z] = r1 + r2;
- }
- }
- data.SetHeights(0, 0, heights);
- }
- void Update()
- {
- SetTerrainHeights();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment