- Home /
How can I change sprites in animation clip?
My project has 2 folders in the Sprites folder: "NRM_Palette" and "GB_Palette"
--EDIT: The current default directory is GB_Palette--
NRM is a copy of the GB Folder but the colours are changed in each of its files. They are otherwise named and sliced the same.
I'm trying to make a mode where the colour scheme of my game changes based on a bool in the Player script: "nrmPalette". Is there a way to have my animation clips (and standalone gameObjects) grab and change their sprites from a specific directory?
I attached this script to each object I want to change, it's based on a video from Unity from 2014, but it's not functioning:
using System.Collections; using System.Collections.Generic; using UnityEngine; using System;
public class PaletteSwap : MonoBehaviour {
public string spriteSheetName;
private void LateUpdate()
{
var subSprites = Resources.LoadAll<Sprite>("NRM_PALETTE/" + spriteSheetName);
if (!Player.nrmPallet)
{
subSprites = Resources.LoadAll<Sprite>("GB_PALETTE/" + 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;
}
}
}