I\'m trying to create an object that will be responsible of creating and showing different sprites, so I would like to access directly the assets/sprites programmatically instea
Here is real code.. will help you
void SetSprite(UI2DSprite uiSprite, Sprite[] sprites, string strKey)
{
foreach (Sprite stexture in sprites)
{
if (stexture.name == strKey)
{
uiSprite.sprite2D = stexture;
break;
}
}
}
use it following the way..
UI2DSprite[] uiSprites = tmpObject.GetComponentsInChildren();
Sprite[] sprites = Resources.LoadAll("Textures");
string resName = "icon_favorite_2";
foreach (UI2DSprite uiSprite in uiSprites)
{
if(uiSprite.name = "icon")
SetSprite(uiSprite, sprites , resName);
}