How do i prevent an object instantiating another object straight away

my c# code below instantiates an array of gameobjects in a range of specific time. It all works fine though except I have a simple problem. In my game I have powerups and the spawner object that is instantiating the powerups instantiates it right where the spawner object is for the first time. so if my spawnMin was 7 and spawnMax was 20 it would rarely instantiate the object which it does but it also instantiates it once as soon as the script is called and it gets spawned right on the position of the object that is spawning it but only once? How do i prevent this?

	public GameObject[] obj;
	public float spawnMin = 1f;
	public float spawnMax = 2;

	void Start () {
		Spawn();
	}

	void Spawn()
	{
		Instantiate(obj[Random.Range (0, obj.GetLength(0))], transform.position, Quaternion.identity);
		Invoke("Spawn", Random.Range (spawnMin, spawnMax));
	}

You are calling Spawn() right away in start. That will call the function as soon as the object is loaded. Also by setting it’s position to transform.position you are using the position of the spawner as your position for the powerup.

Change your Start method to something like this…:

void Start()
{
   InvokeRepeating("Spawn",2f,Random.Range(min,max));
}

and your Spawn to :

void Spawn()
{
  GameObject newobj = (GameObject)Instantiate(obj[Random.Range(0,obj.Length]));

  newobj.transform.Position = new Vector3(Random.Range(minx,maxx),Random.Range(miny,maxy),Random.Range(minz,maxz));

}

A little confused by the wording of your question. What I got is that you have a spawner object, and I assume it is moving around in your game, and randomly you’d like it to spawn power-ups (which we want) but it also always spawns one right away (which we don’t want).

Assuming that, your problem is that your first call to Spawn (in Start) will always be instantly when the script is enabled. Once you’ve called Spawn it’s fine, because within Spawn we are Invoking Spawn, again, with a random time value. Another way to do this would be:

void Start()
{
   Invoke("Spawn", Random.Range( spawnMin, spawnMax));
}

void Spawn()
{
   Instantiate(obj[Random.Range (0, obj.GetLength(0))], transform.position, Quaternion.identity);
   Invoke("Spawn", Random.Range (spawnMin, spawnMax));  
}

tl;dr You need to treat the first call to Spawn like each successive call to it.