1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  3. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
    Dismiss Notice
  4. Unity 5.5 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  6. Unity 5.6 beta is now available for download.
    Dismiss Notice
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
    Dismiss Notice
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.
    Dismiss Notice

Instantiating Sprites

Discussion in '2D' started by MajidKhosravi, Jan 22, 2014.

  1. MajidKhosravi

    MajidKhosravi

    Joined:
    Jun 21, 2013
    Messages:
    30
    Whats the best method of instantiating sprites? I used to use game objects as prefabs and instantiating them using a public reference, however Instantiate function doesn't work with Sprite references.

    Lets say if I have a bullet object as sprite, Should I add sprites to game objects as child and then use those as prefabs to instantiate new items?
     
  2. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Messages:
    345
    You can definitely use prefabs for your sprites. It's the easiest and recommended way to instantiate things.
     
  3. MajidKhosravi

    MajidKhosravi

    Joined:
    Jun 21, 2013
    Messages:
    30
    So should I add my sprite as a child object to a game object and then use that game object as prefab, right?
     
  4. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Messages:
    345
    You can either drag a sprite onto your scene and create a prefab from that or use a child container if you need to.
     
  5. MajidKhosravi

    MajidKhosravi

    Joined:
    Jun 21, 2013
    Messages:
    30
    thanks, it worked! :)
     
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Messages:
    5,632
    You can also just in create a new gameobject (programmatically) and attach a spriterenderer to it.
     
  7. sub66pop

    sub66pop

    Joined:
    Jan 11, 2014
    Messages:
    3