Unity3d load sprite from Textures folder

filipst picture filipst · Jun 25, 2014 · Viewed 12.1k times · Source

I have around 200 sprites (jpg pictures) in Assets>Textures>Pictures, and I have GameObject with <SpriteRenderer>. Is there a way for me to load sprites from that folder into this GameObject in code? Something like Resources.Load<Sprite>("path");

Thank you.

Answer

apxcode picture apxcode · Jun 25, 2014

Put your folder inside the Resources folder. Like this: Assets/Textures/Resources/

Then you can do this:

private Object[] textures;

void Awake()
{
    textures = Resources.LoadAll("Path");
}

You have to store them as Objects. However, if you want to use them later you can do something like this.

texture = textures[i] as Texture;