- Home /
Question by
Ted24 · Dec 06, 2015 at 02:49 PM ·
spritesresources.load
Does Resources.Load work with Sprites?
I try to assign certain sprites to my gamefield elements with this code
myEl[i].sprite= Resources.Load(myEl[i].name+"_"+spritesArray[i].ToString());
but get nothing. Sprites located in Resources/folder/folder/xx_nn.png. If i use Resources.LoadAll and array it works good, but too slow because in that case more than 7k sprites loaded.
Comment
Best Answer
Answer by static_cast · Dec 07, 2015 at 07:52 PM
You need to have the directory path in your load, don't you?
Hm, very strange. I tried it before. At the end it worked with "folder/folder/name"
Answer by ReezooBose · Dec 09, 2015 at 09:06 AM
string texturepath = "Assets/Resources/Textures/YourSpriteName.png";
Texture2D loadedTexture = Resources.Load("texturepath") as Texture ;
Renderer rend = GameObject.GetComponent<Renderer>();
rend.material.mainTexture = loadedTexture ;
I have considered you have Folders In this order : Assets----->Resources------->Textures-------->sprite that you want to load ;