I’m looking to make the best use of Unity’s built-in sprite slicing mechanisms, but am having trouble referencing them from my back-end.
private string spritePiece = "Game_Assets/spritesheets/Items/SpriteSheet_Blade01_FallenSword";
void Start() {
var spriteRenderer = GetComponent<SpriteRenderer>();
var LoadedSprite = Resources.Load<Sprite>(spritePiece);
spriteRenderer.sprite = LoadedSprite;
}
Works just fine for loading the first piece in this sprite slice, but I really need “Game_Assets/spritesheets/Items/SpriteSheet_Blade01_FallenSword_0” and other subsequent sliced pieces. I tried a few things like getting back an array/list, and Unity can’t seem to handle that concept.
Any suggestions? I’m just looking to palette-swap some assets and this is becoming ridiculously frustrating and convoluted.
Post-Resolution:
The answer was, as provided below, to use Resources.LoadAll instead of Resources.Load, then use the index of the array which was returned to apply the sliced portion of the sprite.
Code:
private string spritePiece = "Game_Assets/spritesheets/Items/SpriteSheet_Blade01_FallenSword";
// Use this for initialization
void Start() {
var spriteRenderer = GetComponent<SpriteRenderer>();
var LoadedSprite = Resources.LoadAll<Sprite>(spritePiece);
spriteRenderer.sprite = LoadedSprite[1];
}