- Home /
Question by
naderlabbad309 · Jul 29, 2019 at 06:12 PM ·
c#terraindestroytreemesh renderer
RTS game Any help about Hide mesh or destroy trees Terrain?
Hello all
I am developing RTS game I worked on it for a long time But now stuck with Hide or destroy trees Terrain
When I build buildings Put it down Be Inside trees Is there a way to destroy or hide mesh ?
I'm looking long and I can not find a solution
I'm already stuck with this Is there any idea ?
Comment
Best Answer
Answer by naderlabbad309 · Jul 30, 2019 at 08:05 PM
public float distance = 0;
public float distanceG = 0;
public float closeRange = 40;
public Terrain terrain;
void Start()
{
}
void Update()
{
TerrainData terrain = Terrain.activeTerrain.terrainData;
ArrayList instances = new ArrayList();
foreach (TreeInstance tree in terrain.treeInstances)
{
distanceG = Vector3.Distance(gameObject.transform.position, tree.position);
distance = Vector3.Distance(Vector3.Scale(tree.position, terrain.size) + Terrain.activeTerrain.transform.position, transform.position);
if (distance < closeRange)
{
// the tree is in range - destroy it
print("1");
}
else
{
// tree is out of range - keep it
instances.Add(tree);
}
}
terrain.treeInstances = (TreeInstance[])instances.ToArray(typeof(TreeInstance));
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Deform of terrain? (Real-time) 0 Answers
Deleting Terrain Trees Dynamically 1 Answer
How Do I Interact With Terrain Trees? 2 Answers