Can an animation’s sprite sheet be changed programatically? I know that I can use mecanim to define different animation states and set bools/triggers, etc. etc., but that’s not what I mean.
I have an enemy that uses sprite sheet animation. He has the ability to lose limbs, so I have sprite sheets for each permutation of lost limbs (no left arm, no right arm, no arms, no head and no left arm, no head and no right arm, etc.), and color variations of each of those permutations. In total, I have like 20 sprite sheets for this one enemy, and I really don’t feel like defining a separate animation state for each. I can do it if I have to, but I was hoping I could do something like this (pseudocode) to save some time:
public SpriteSheet allLimbs;
public SpriteSheet noLeftArm;
public SpriteSheet noLeftArmNoHead;
public SpriteSheet noArmsNoHead;
...
public enum Limb{
Head, LeftArm, RightArm
}
public void LoseLimb(Limb limb){
if(limb == Limb.Head){
SwitchSpriteSheet();
...
} ...
...
}
Can this sort of thing be done natively in Unity? If not, it’s probably quicker just to do the individual animation states for my purposes, rather than write a custom SpriteSheet class and parse image data.
Just a note,, in case it's not possible (I really hope it is though, since I ned it for my project as well): Consider using a shader that supports palettes, this way you can assign different palettes based on the damage your character receives (use transparent colors for holes in the body). Of course, the spritesheet bitmap has to be set up the right way so that each possible damage area has it's own color.
– ChernoWhat is the SpriteSheet class you're using? Unity's own Sprite atlas, or a third party such as Texture packer? If your sprites are always arranged in the same layout on each sheet, is it not just a case of changing the renderer.sharedMaterial.mainTexture to the appropriate sheet?
– tanoshimi@tanoshimi That's just pseudocode. I don't actually have a SpriteSheet class. That's just something like what I was hoping to accomplish. I'm using all stock Unity stuff in my project, and using frame animation from the spritesheet using animations in mecanim. All of my spritesheets are exactly the same in dimensions and number of frames. I'll look into the solution you've mentioned, but I have a feeling the animation will overwrite any sprites/textures I assign through code. I suspect I'll have to access the Animator in order to achieve what I'm looking for.
– jakejolli