Spawn Multiple?

How to make it to spawn in group instead of one by one ?

var wave1: GameObject;
var wave2: GameObject;

function Start() {
Spawn();
}
function Spawn() {
   for (t=0;t<3;t++) {
      yield WaitForSeconds(5);
      Instantiate(wave1, transform.position, transform.rotation);
   }
   for (t=3;t<10;t++) {
      yield WaitForSeconds(5);
      Instantiate(wave2, transform.position, transform.rotation);
   }

}

Well, being as Instantiate only creates an instance of one object at a time I’m not sure there is a way to make a group of objects without some sort of a repeat loop like you’re using. Is there a reason the technique you cited isn’t acceptable?

If you just remove the yield it will spawn them all at the same time. Then you just need to spread the position a bit around so that they wont all spawn at the exact same position. You can use the Random class for that.

Perhaps you could get 3 enemies or more, create a prefab, drag the three on top of that empty prefab and instantiate that instead?

AC

Thanks for the advise! yes i was thinking to make few prefab, but just wondering if its able to script it so it looks more tidy, maybe i can try using the random class. :slight_smile:

Create a for inside a for

.ORG