Jacksinthe
Banned
Yes, but the devil is in the details.
Then let's take it a step further to simplify without using overlays of objects.
Have your original character already pre-sliced into, say, upper costume, lower costume, etc.
For each of these objects, get the name of the current sprite and replace it with the corresponding sprite from another costume from an array. We do this to change costumes for our character using a similar method, except we just change the entire character.
Our normal sprites are numbered 0-X.
0 is idle
1-6 is run
7-10 is jump
so on
I use a bool to denote which costume is being worn and assign a new sprite from a new costume array.
So we don't have to create an array ahead of time and assign every damn sprite - I create an array at runtime and pull a set of sprites alphanumerically from a specific costume folder and assign them to the new array, 0-X again. Each new sprite is numbered with a prefix, with the exact same animation state per sprite so 0 in the new array will be idle, 1-6 run, etc.
Now if my bool says "blacksuit" is true - i simply assign a new sprite from the array:.
Unity C#
Code:
if (blacksuit)
_renderer.sprite = _costume.blacksuit[int.Parse(_renderer.sprite.name)];
So what we are doing is assigning a new sprite in the renderer from an array from our costume class called "blacksuit". Inside that array i am grabbing the current sprite's name and turning it from a string to an int. Since my sprites are all numbered 1-X - it parses 1:1.
You can do something similar for your costume objects. This way you're not adding, overlaying and removing objects, you simply use one and change the sprite based on whatever sprite is supposed to be there.
I often screw around and have my dude change into random enemies XD
I should make a cardboard box.