- Home /
Question by
MerlinsMaster · Jan 28, 2016 at 07:59 AM ·
resourcesspritesheetloadall
Trying to use Resources.LoadAll to change sprite sheets during runtime
Hey Guys,
I'm trying to use a script that a Unity tech showed in a video lecture that allows you to change sprite sheets during runtime (presumably so a character can change clothes or personal items that they might be holding).
The problem is, I can't seem to get it to work. This is the script:
using UnityEngine;
using System;
public class ReSkinAnimation : MonoBehaviour
{
public string spriteSheetName;
void LateUpdate ()
{
var subSprites = Resources.LoadAll<Sprite>("Sprites/" + spriteSheetName);
foreach (var renderer in GetComponentsInChildren<SpriteRenderer>())
{
string spriteName = renderer.sprite.name;
var newSprite = Array.Find(subSprites, item => item.name == spriteName);
if (newSprite)
renderer.sprite = newSprite;
}
}
}
If anyone has seen this before and knows how it works, could you please show me how this works in an example? More specifically, how does this relate to the game object with the sprite attached?
Comment