- Home /
Problem is not reproducible or outdated
Why does my tree script not work
Hi , so I know another {one} about trees not using scripts because there not actual gameObjects....
So I ended up making a working cut the tree down script... but when I went to mass place the tree prefabs ... The script ended up nulling out that goes with the tag reverting back to default instead of " Tree ". So I looked threw the documentation and found terrainData and treeinstantce ... so I wrote a for loop and have a loading screen wait untill all the "Fake tree objects are created " meaning just the collider with a tree damage script " Java script "
The problem i'm having now is that .... ok it creates the number of trees for treeInstances so if I have 10 trees 10 fake tree objects with collider , if I have 20 ,... 20 fake tree objects suberb .... Ok there being made its loading , loading done.... HUH! the trees are all at 1 position on the corner of the terrain so I know I wrote the terrain positions array wrong and im not sure so much on how the positions are stored.... for the terrain data ...
Here is a snap shot of whats happening :
Here is my script :
//This script finds all the terrain's trees then creates the tree object for user interaction for each tree position
var treeFab : Transform;
var grabTerrain : Terrain;
function Start () {
for (i=0; i <Terrain.activeTerrain.terrainData.treeInstances.Length; i++)
{
//var treeInstances : TreeInstance = new Terrain.activeTerrain.terrainData.TreeInstance();
Instantiate(treeFab, Terrain.activeTerrain.terrainData.treeInstances[i].position, Quaternion.identity);
}
}