13
\$\begingroup\$

Unity 4.3 newly brings an ability to cut up a sprite sheet into multiple individual sprites. This is useful since you then only need one master spritesheet, but nevertheless get references to individual sprites. It's done by setting Sprite Mode to Multiple.

Can all the sprites generated from the master file be programmatically accessed from the Unity Sprite Editor?

For example: I have a spritesheet with a grid of 50x50 sprites. Using the Unity Sprite Editor, I now have 250 sprites: spritesheet_0, spritesheet_1, ..., spritesheet_249. How can I get a handle to spritesheet_102 without having to manually drag and drop it in the Unity editor?

\$\endgroup\$
6
\$\begingroup\$

You need to create a sprite array Sprite[] sprites and fill it using sprites = Resources.LoadAll<Sprite>("Location"); inside Awake().

\$\endgroup\$
  • \$\begingroup\$ Also make sure all sprites are in Resources folder to use Resources.LoadAll(). \$\endgroup\$ – Rajneesh Gaikwad Jun 1 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.