- Home /
How to Address Texture2D Elements from a Sprite with Sprite Mode: Multiple, in Code?
Hi, how could I Address these nice sliced Textures from a Sprite with Texture Mode: Multiple in Code? I can see that they got nice names with [name]_0,[name]_1,[name]_2,... but i cant Drag the root element in a Texture2D List. I want to make a Tile based 2Dt Map with 50 or more Tile Types and i downt want to make 50 public Texture2D variables or a List in my Class and Drag and Drop each Tile.
Comment
Answer by Mefistofel · Nov 14, 2013 at 05:23 PM
I posted a question on the same theme 15 minutes later :)
You can load an array of all the sprites in the atlas with Resource.LoadAll(textureName) and then choose sprite by the name in the array. Who knows more ways?
Here people also came to the same:
Sprite[] sprites = Resources.LoadAll<Sprite>("Textures");
or
Sprite[] textures = Resources.LoadAll<Sprite>("Textures");
string[] names = new string[textures.Length];
for(int ii=0; ii< names.Length; ii++) {
names[ii] = textures[ii].name;
}
Sprite sprite = textures[Array.IndexOf(names, "textureName")];