The Idea, is to create a almost empty terrain. It would have Hills, water, etc, already setup on it, but thats it.
I would like to find a way to make a script, maybe attached to the terrain itself, not sure where it would be attached, but the script would load when the level is generated, spawn diffrent things in set numbers, like spawn 50 trees, 20 rocks, etc, and randomly place them around the map. Problem is it would spawn anywhere, no limits, so trying to find a way to tell it to only spawn if the terrain is a certain hieght. The map is at 10y, water ways are at 0, and the hills/mountains are 50 plus there over hand/blending to the lower terrain.
Trying to find a way to make a script that would randomly generate a set of cords within say 100p of the edge so nothing over hangs/grows past the boundries, but to sample the height and if its at 100 or more away from the edge, and the height on the terrain is 10, place the tree, if not find somewhere else. I was using a invis marker, ploped down a cube, made it invisible, attached a script around the lines of
//var centerMark : Transform;
//var preFab : Transform;
//var numberTargets : int;
//var radius : float;
//function Start()
//{/
//var position :Vector3;
//var i : int;
//for(i = 0; i< numberTargets; i++)
//{
//position = Vector3(player.position.x + Random.Range(-radius,radius),0.0f,player.position.z + Random.Range(-radius,radius));
//position.y = Terrain.activeTerrain.SampleHeight(position) + Terrain.activeTerrain.transform.position+y; //I had a student move the terrain on me necessating adding the y position of the terrain
//var target = Instantiate(preFab, position, Quatenrion.identity);
//target.transform.position.y = target.transform.position.y + target.transform.collider.bounds.size.y/2;
//}
//
//}
This sorta works, but then leaves a problem of it still spawns everywhere regardless of water, hill, etc, and since the player can place objects or prefabs down, sometimes it spawns inside other objects. Any ideas on a easy way to work this out?