Download the Unity3d sprite from the Textures folder

I have about 200 sprites (jpg-picture) in Assets>Textures>Pictures, but I have GameObjectto <SpriteRenderer>. Is there any way to load sprites from this folder into this GameObjectcode? Sort ofResources.Load<Sprite>("path");

Thank.

+4
source share
3 answers

Put your folder in the "Resources" folder. For instance:Assets/Textures/Resources/

Then you can do this:

private Object[] textures;

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

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

texture = textures[i] as Texture;
+5
source

Well solution Resources.Load<Sprite>("path")for one sprite or Resources.LoadAll<Sprite>("path"), if you want to download them all at once.

, "" , Assets/Textures/Pictures/Resources.

:

, "" "", "" . "" , .

Unity , , -, . Unity , . , . "" , , "" .

+4

awesome.png Assets/Resources/ ( ) :

GetComponent<SpriteRenderer>().sprite = 
    Resources.Load<Sprite>("awesome");  // No file extension.

http://docs.unity3d.com/ScriptReference/Resources.html

LoadAll, " " ".

0

Source: https://habr.com/ru/post/1546009/


All Articles