Search Unity

Adding instantiated object to empty GameObject

Discussion in 'Scripting' started by matthewminer, Oct 29, 2006.

  1. matthewminer

    matthewminer

    Joined:
    Aug 29, 2005
    Posts:
    331
    To help me learn Unity, I'm making a clone of space invaders. To save me from creating each enemy individually, I have a script that instantiates them from a prefab. Now, how do I add these newly created objects to an empty GameObject? I'd like to create a script that moves this GameObject side-to-side, but I can't figure out how to make the enemies a child of the GameObject.

    Thanks for any input.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  3. matthewminer

    matthewminer

    Joined:
    Aug 29, 2005
    Posts:
    331
    Thanks, that lead me in the right direction. The code that ended up working for me looks like the following (only slightly different from what you gave).

    Code (csharp):
    1. enemyClone.transform.parent = enemyParent;
     
  4. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    Welcome Teilas, and good luck getting your Space Invaders game finished! If you complete it to your satisfaction, please upload it or post a link so we can all enjoy it. I personally am curious about what a Unity space invaders clone looks like!

    Good luck ask any questions around here! :p