Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Newbie problem: prefab with many different sprites.

Discussion in '2D' started by gecenab, Mar 23, 2018.

  1. gecenab

    gecenab

    Joined:
    Jan 22, 2018
    Posts:
    2
    I want to create a prefab object that changes its form (sprite) when instantiated. Pretty much a spawn point that creates different types of enemies with similar characteristics.

    Is this easier by creating a prefab that contains different child or o single prefab with many sprites? In any case can I get any notes on how to do this? I've read some old threads but the idea isn't clear.

    Second thing... how can I make enemies spawn every n seconds?

    Thanks
     
    Last edited: Mar 23, 2018
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    It depends on if you want the enemy to have different properties, or if you only want it to use different sprites. You can create an array in your spawn script, make it public so that you can drag in different GameObjects into it and then choose a random one when you spawn it.

    An easy way to have something occur every n second is to use InvokeRepeating:
    Code (csharp):
    1. InvokeRepeating("Name of method to invoke", n);
     
  3. gecenab

    gecenab

    Joined:
    Jan 22, 2018
    Posts:
    2
    Thanks!