So, I have a texture with TextureType: Sprite and SpriteMode: Multiple in Unity 4.3.
I used a Sprite Editor to cut out some Sprites from my texture.
Now my sprites are showing as children in the Project window.
How can I access these children in the code?
Lets say Im writing my class and using
public Texture2D txt;
to set a texture in the inspector (by drag and dropping it).
But later I want to access Sprites inside this texture in the code. How ca I do it?
For anyone searching for this topic, it should be noted that there’s a new way of doing this.
In Unity 2017 SpriteAtlas was added. You can make one from the Create menu. If you add a multi-sprite texture to an atlas, you can access the child sprites by using spriteAtlas.GetSprite(“child_sprite_name”), (you can change the individual sub-sprite names in the sprite editor) or get all of them with GetSprites(spriteArray).
Then you can just grab a Sprite by name from the static atlasCardfront.
This static function should be called from the static constructor of this class. This all depends on your project and class setup but you probably want to cache the sprites vs filenames early.