Quantcast
Viewing latest article 3
Browse Latest Browse All 6

Any Reason this would make Unity Freeze up?

private void PlantTrees(){ int treeTypes = terrain.terrainData.treePrototypes.Length - 1; int maxZ = (int) terrain.terrainData.size.z, maxX = (int) terrain.terrainData.size.x; for(int z = 1; z < maxZ; z++){ for(int x = 1; x < maxX; x++){ TreeInstance tree = new TreeInstance(); float height = terrain.SampleHeight(new Vector3(x,0,z)); if(height > res*0.2){ if(Random.value > .6){ float r = Random.Range(80f, 120f), g = Random.Range(100f, 150f), b = Random.Range(20f, 80f); tree.color = new Color(r,g,b); tree.heightScale = Random.Range(0.5f, 2f); tree.widthScale = Random.Range(0.75f, 1.25f); tree.position.Set(x, height, z); tree.prototypeIndex = Random.Range(0, treeTypes); terrain.AddTreeInstance(tree); } } } } } I know this is incredibly vague, but I know it's this bit of code because it runs fine when I comment out the function call. I am at a complete loss at this point, if anyone has a tiny bit of knowledge on this I would greatly appreciate it. On a side note for some reason this places all the trees in the same place despite having the positions changed... Any ideas why? I have a feeling it's the way I'm instantiating the trees, but I don't know why that wouldn't work.

Viewing latest article 3
Browse Latest Browse All 6

Trending Articles