Procedural Top Down Levels

I'm building a top down game wherein I wish the environment around the player to be generated randomly. Essentially I wish objects to be spawned out of the view in a radius around the player and the be destroyed when they are a certain distance away. At this stage it can just be a single object.

Before I attempted to build this myself I wanted to ask a few more experienced Unity users how they would tackle this question?

I was thinking of perhaps using a Bounds where the area between the extents and size was the spawnable area, however I'm at a loss on how I would calculate points only in that area.

Thanks, any help is much appreciated, ~Hawk

You can use something like this:

var p : Vector3 = Random.insideUnitSphere * maxSpawnRange;
p.y = 0;
if (p.sqrMagnitude >= minSpawnRange*minSpawnRange) {
    p += player.transform.position;
    //Spawn the object at position P

It will generate a random position but discard it if the position is too close to the player.

You can use the same principle when destroying objects too far away:

if ((transform.position - player.transform.position).sqrMagnitude > destroyRange*destroyRange) {
    Destroy (gameObject);

Run this code every second or so.