Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Terrain Modification Script index out of range?

$
0
0
I am making a script to make my terrain blocky like in minecraft but since I am new to unity3d's terrain class it is proving a challenge, I do not know why but I get a IndexOutOfRangeError on line 23. Also if you see any other problems please tell me! Thanks! Code: using UnityEngine; using System.Collections; using System.Collections.Generic; public static class TerrainToBlocks { public static int xRes; public static int yRes; public static void GetTerrainValues(TerrainData td,GameObject terrainObject){ Debug.Log ("Started"); xRes = td.heightmapWidth; yRes = td.heightmapHeight; float[,] heights = td.GetHeights (0, 0, td.heightmapWidth, td.heightmapHeight); RoundNumbers (xRes,yRes,heights,terrainObject); Debug.Log ("Step 1 Complete."); } private static void RoundNumbers(int x, int y,float[,] old,GameObject terrainObject){ float[,] newHeights = new float[xRes,yRes]; for(int i = 0; i < x; i++){ for(int k = 0; i < y; k++){ newHeights[i,k] = Mathf.RoundToInt(old[i,k]); } } GenerateBlocks (newHeights,x,y,terrainObject); Debug.Log ("Step 2 Complete."); } private static void GenerateBlocks(float[,] hMap,int x, int y,GameObject terrainObject){ for(int i = 0; i < x; i++){ for(int k = 0; i < y; k++){ float xVal = (float)i; float yVal = (float)hMap[i,k]; float zVal = (float)k; Vector3 pos = new Vector3(xVal,yVal,zVal); GameObject newCube = GameObject.CreatePrimitive(PrimitiveType.Cube); newCube.transform.position = pos; } } Object.DestroyImmediate (terrainObject); Debug.Log ("Terrain Generation Finished."); } }

Viewing all articles
Browse latest Browse all 7934


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>