Hello there,
I’m pretty new to Unity and I stumbled upon this problem.
Here is the animation for a hand that changes the sprite, to look like it’s dragging something ( moves on top of an object, presses the object, moves somewhere else then releases it ). It has 2 instances : handUp and handDown.
I have the same 2 instances drawn for the same hand, but with different colors.
I want to use the same animation, but change the sprites at runtime.
How should i achieve this ?
Should I make another .anim and change it in the Animator for the other hand ? I would use this, but i have A LOT of things that require the same sprite changing. Plus, not only for this hand, but for other stuff, i have about 9 color schemes that i need to swap. I don’t really feel like making 9 .anim for each element in the game and swap them. There needs to be another solution.
The other animations are some seahorses that are moving, blinking and some starfishes, clams, pretty much everything …
Thank you
I tried a few weeks ago to have a similar effect. Was with megaman, when you press the key yo shoot, its legs should continue as-is, and not restart the animation from the beginning. So instead of duplication all the animations with the gun out, I added an animation event (a function named “OnUpdatedAnimation” taking an int) and the script looks like:
using UnityEngine;
using System.Collections;
public class MegamanScript : MonoBehaviour {
private SpriteRenderer spriteRenderer;
private Animator anim;
private bool IsShooting;
private int lastID;
public Sprite[] shootingSprites; // filled in the editor
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
anim = GetComponent<Animator>();
IsShooting = false;
}
void Update()
{
var h = Input.GetAxis("Horizontal");
var j = Input.GetKey(KeyCode.J);
IsShooting = Input.GetKey(KeyCode.Space);
anim.SetBool("Grounded", !j);
anim.SetFloat("Speed", h);
}
void OnUpdatedAnimation(int id)
{
if(IsShooting)
lastID = id;
}
void LateUpdate()
{
if(IsShooting)
spriteRenderer.sprite = shootingSprites[lastID];
}
}
It’s probably not the best way to do it, but it works. In your case, you could add a dimension to the array and having:
spriteRenderer.sprite = shootingSprites[colour][lastID];
I understand what you are trying to do, but if i change the sprite from the sprite renderer and still play the animation, the Sprite curve from the animation will override the sprite that i set in the sprite renderer, showing me the basic hand with basic colors.
If your animation consist only in changing sprites you can try this script from Alec Holowka SpriteAnimator.cs - Pastebin.com
If you can’t understand it just ask and i will try to help you 
This might actually help me. I briefly went over it and it seems just what I need. I have to figure out how it actually works.
Thanks a lot for the quick responses.