Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Instantiate in one frame.

Discussion in 'Scripting' started by phi_mai, Mar 25, 2016.

  1. phi_mai

    phi_mai

    Joined:
    Mar 24, 2016
    Posts:
    8
    Hi guys!
    I'm wondering are there a way to instantiate multiple prefabs in one frame?
    Code (CSharp):
    1. void Start ()
    2. {
    3. Instantiate(eBox, new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 1f), Quaternion.identity);
    4. //if I want to instantiate 10 of these, I have to copy and paste 10 more commands
    5. }
    My point is to use one small code to control Instantiate multiple prefab within one frame.
    Thank you for your time.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Never copy/paste; use loops/arrays as appropriate.

    --Eric
     
    phi_mai likes this.
  3. phi_mai

    phi_mai

    Joined:
    Mar 24, 2016
    Posts:
    8
    Thank you so much!