0

So I'm implementing a skin system in my 2D game so I did the sensible thing and named all my skin sprites 0 till 29 for easier indexing. Now I'm trying to load them onto my player character depending on the currently selected skin. So I created the following code which should work fine but doesn't.

private Sprite spr;

void Start () {
    spr = Resources.Load<Sprite>("Assets/Skins/" + PlayerPrefs.GetFloat("currentSkin").ToString());
    GameObject.Find("player").GetComponent<SpriteRenderer>().sprite = spr;
}
Daan Koning
  • 155
  • 2
  • 15
  • Just a comment on the naming: this can work but there's also nothing wrong with a lookup table/structure. The benefits of a lookup is that you can reindex things or rename things in the table without having to renumber your images. You can also add additional metadata (skin description for example) and load/list skins by their metadata in selection screens. – Charleh Oct 14 '18 at 18:14
  • You're feeding incorrect path to the `Resources.Load` function. The path also has to be placed in the Resources folder and the path must be relative to that folder – Programmer Oct 14 '18 at 18:21

0 Answers0