- Home /
Question by
VortexStudios · May 16, 2015 at 01:43 AM ·
arrayspriteframesprite sheet
put every sprite frame in a array
hello everyone, my question is very simple, I'd like to get every sprites from a spritesheet and put in a array, there any way to do that??
thanks :)
Comment
Answer by smallbit · May 16, 2015 at 07:47 AM
IF you dont need to get them on runtime just go to sprite settings change type to multiple and edit. Once you are done, create a script with an array:
publc Sprite[] mySprites;
Than drag it into scene to a gameObject, and from project view expand sprite selection and drag every single sprite into mySprites array in the inspector view in your script. Than you can use them in your spriteRenderers:
public SpriteRenderer myImage;
//
void ChangeSprite(int number)
{
myImage.sprite = mySprites[number];
}
But if you actually need to load them during runtime please refere to this topic - >http://answers.unity3d.com/questions/579791/how-do-i-access-the-individual-frames-of-a-sprite.html