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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Best implementation for 2D character skins

Discussion in '2D' started by GurinJaw, Nov 26, 2015.

  1. GurinJaw

    GurinJaw

    Joined:
    Sep 12, 2015
    Posts:
    1
    Excuse me, I've wanted to create skins for my game's main character, and I was wondering about the best way to implement it with the limitations of the mobile capabilities in mind, the processing, RAM etc., what I had in mind was basically simply putting ALL skins on my character at the same time, and switch between them using gameObject.setActive(false);
    So is that a good way to implement it? Or will the fact that they all exist in the same time be consuming to the memory and inefficient at all? Is there some other way to like, instantiate them from somewhere and just input the positions and call it a day? Thank you in advance, I really appreciate any advise I would get ^_^
     
    mrsteamfist likes this.
  2. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    If it's a skin, and there isn't much difference between the shapes, just switch the sprite [:)] Store the skins in an array, and assign them to the sprite renderer when you needed using this:
    Code (csharp):
    1.  
    2. public Sprite[] skins;
    3.  
    4. void ChangeSkin(int skinToUse)
    5. {
    6. gameObject.GetComponent<SpriteRenderer>().sprite = skins[skinToUse];
    7. }
    If you have any questions, just ask [;)]
     
    mrsteamfist likes this.
  3. mrsteamfist

    mrsteamfist

    Joined:
    Nov 3, 2015
    Posts:
    19
    Suppose I want to have some downloadable skins. Do you have any suggestions for that?
     
  4. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Ah, now that's a bit trickier. You would have to look into WWW classes (Which work not only for URLs but for hard drive paths too). I've personally only glanced over runtime asset loading, so I can't give you a code example.
     
    theANMATOR2b likes this.