Instantiate prefabs without overlapping

Hi all, im making a flappy birds type clone, I have for example 10 different obstacle prefabs, each is a different size, im trying to get the code to instantiate one of the obstacles randomly, but with them being different sizes im having trouble getting them to be (a)off screen so you don’t see them appear and (b) close enough to the previously generated obstacle without overlapping it. ive tried several different ways, for example having it appear at players position x+30, and having a last obstacle size variable to determine when next obstacle can be generated, this still creates uncertaintys and over lapping.

Any help from you guys would be greatly appreciated.

Thanks

a timer would only work if the players speed was consistent, you can reference how far the player has travelled and then instantiate one.

//pseudocode because i dont know your variables


float xTravelled;
float minSpawnDistance = 20;

void Start() 
{
xTravelled = transform.position.x; //players x
}


void Update()
{

if(transform.position.x - minSpawnDistance > xTravelled )
{
//you can add a random chance to spawn here
xTravelled = transform.position.x;
}

}

you need to make an overlapSphere with your object position center as its center and bounds extent magnitude as its radius and check for all the colliders in this boundry if thier bounds intersect with new object bounds

 bool isOverlapped = false;
 Bounds bounds = renderer.bounds;
 Collider[] cols = Physics.OverlapSphere(transform.position, bounds.extents.magnitude);
 foreach(Collider col in cols) {
     if (col.gameObject == gameObject) {
         continue; 
     }
     if (bounds.Intersects(col.gameObject.renderer.bounds)) {
         isOverlapped = true;
         break;
     }
 }