I am trying to create a 2D game in Unity in which objects keep falling from top and the player has to dodge them. Suppose I have created a sprite which serves as a single enemy that the player has to dodge.Now I have to create multiple such sprites at runtime so that they can keep on spawning from random positions.Despite searching on the net for quite some time i could not find a clear answer.

I am just a newbie and I am just starting to learn game development in Unity so answers in detail will be very helpful.

Thanks in Advance.


You do it in Unity by creating prefabs in editor (see video) and then instanciating them in script (read manual) or in editor.

  • \$\begingroup\$ Thank you very much I got what I was looking for. Could you explain how to destroy the prefabs once they are out of scene. \$\endgroup\$ Oct 13 '15 at 11:50
  • \$\begingroup\$ You are welcome. Prefabs are not destroyed, they are static to projects (i.e. shared between scenes). But objects instanciated from a prefab are destroyed as usual by calling Destroy(obj1). \$\endgroup\$
    – Igor S.
    Oct 13 '15 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .