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.

1 Answer

1

I posted a question on the same theme 15 minutes later :slight_smile:

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][1] 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")]; [1]: http://answers.unity3d.com/questions/576153/loading-a-sprite-unity-43-in-resource-folder-and-s.html