Hi all,
I’ve been using the following script with Unity 3.4 but it’s not working correctly with 3.5 beta. Simply place this script on your water and it should remove all trees below the waterline
…well in 3.4 it removes all trees below the waterline but in 3.5 it removes many trees from above the waterline as well.
Any tips on getting this working on 3.5 beta?
Thanks
var vegHeight : float;
function Start(){
vegHeight=transform.position.y;
RemoveTrees();
}
function RemoveTrees(){
terraindata = Terrain.activeTerrain.terrainData;
terrain = Terrain.activeTerrain;
var instances : ArrayList = new ArrayList();
for(var i : int = 0; i < terraindata.treeInstances.length; i++){
var instance : TreeInstance = new TreeInstance();
instance = terraindata.treeInstances[i];
var pos = instance.position;
pos = terrain.gameObject.transform.position + Vector3(pos.x * terraindata.size.x, pos.y * terraindata.size.y, pos.z * terraindata.size.z);
if(terrain.SampleHeight(pos) > vegHeight){
instances.Add(instance);
}
}
terraindata.treeInstances = new TreeInstance[instances.Count];
terraindata.treeInstances = instances.ToArray(typeof(TreeInstance));
//terraindata.RecalculateTreePositions();
terrain.Flush ();
}