Get sprite atlas name
I am currently loading a sprite from an atlas using this:
public Sprite[] getSprites;
getSprites= Resources.LoadAll<Sprite>("tiles2");
and then assign a new one programmatically like this:
this.GetComponent<SpriteRenderer>().sprite = getSprites[6];
So it will set the 7th tile from the atlas to the sprite.
My question is ....how can i get the name of the atlas the sprite is using, so i can then check its name and load a different one when i want ?
I know i can get the tile name like this:
string tileName = this.GetComponent<SpriteRenderer>().sprite.name;
But i cant figure out how to do the atlas.
Answer by Statement · Oct 24, 2015 at 06:33 PM
First, get the texture of the sprite, then get the name of the texture.
string tileTextureName = GetComponent<SpriteRenderer>().sprite.texture.name;
jesus..lol I tried ...().texture.name.... didnt think of going for sprite as well :P
Thanks
I just want to write that I tried this and for some reason got a really long name (instead of the Atlas's name). My real atlas name is : "TileAtlas_MossBrick_Outline" But when I via a code and a sprite accessed its name I got: "sactx-0-1024x1024-DXT5-TileAtlas_MossBrick_Outline-07e24639" Does anyone know why this is? Thanks!
Your answer
Follow this Question
Related Questions
MissingFieldException: UnityEngine.SpriteRenderer.sprite 0 Answers
Get sprite size and position 0 Answers
Change sprite size programmatically 0 Answers
the image set on the inspector is not displayed. I am a beginner 2 Answers
Sprite Atlas bug on Android 6? 0 Answers