Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Spawn Multiple?

Discussion in 'Scripting' started by Hansuke, Jun 26, 2007.

  1. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    How to make it to spawn in group instead of one by one ?

    Code (csharp):
    1. var wave1: GameObject;
    2. var wave2: GameObject;
    3.  
    4. function Start() {
    5. Spawn();
    6. }
    7. function Spawn() {
    8.    for (t=0;t<3;t++) {
    9.       yield WaitForSeconds(5);
    10.       Instantiate(wave1, transform.position, transform.rotation);
    11.    }
    12.    for (t=3;t<10;t++) {
    13.       yield WaitForSeconds(5);
    14.       Instantiate(wave2, transform.position, transform.rotation);
    15.    }
    16.  
    17. }
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    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?
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    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.
     
  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    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
     
  5. Hansuke

    Hansuke

    Joined:
    Apr 17, 2007
    Posts:
    100
    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. :)
     
  6. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Create a for inside a for

    .ORG