- Home /
Multi sprite characters order themselves as a whole rather than as individual parts
So I have a bunch of zombies that are made out of several sprites so that it's easy to animate and change parts around. The zombies themselves layer fine but when multiple zombies are near each other the individual parts of each overlap and this causes layering problems.
The only solution I can think of it to change the order in layer of every individual part of a zombie each time one spawns but that seems really inefficient. Is it possible to have the zombies order themselves instead of each individual part? So one zombie will be completely on top of another rather than only half of him being on top.
Answer by Kiwasi · Sep 30, 2014 at 01:07 AM
Change the order of layer for each individual part for each zombie. Pseudo code as follows:
static int zombieNumber;
void Start (){
zombieNumber ++;
foreach (sprite in zombie){
sprite.sortingOrder = sprite.sortingOrder + 100 * zombieNumber;
}
}
You can go as high as you want (almost) with sorting order. So there shouldn't be any problems with this approach.
Shouldn't be a problem if a reset the counter once it hits 1000. This should work well! Quick question, is it cheaper to make a public variable for the sprite renderer of each part on the base and then drag in each sprite so I don't have to use getcomponent or should I just go with getcomponent?
GetComponent is cheap enough if you use it once then store the reference.
I wouldn't worry about the cost of GetComponent until you start hitting frame rate issues.
@Tepei $$anonymous$$y understanding was it was implemented as an int32, as opposed to an int16. Are you aware of any documentation that says otherwise? The default for C# appears to be an int32
I have no particular use for this information at the moment, but I like to have the correct details in case I need them.
I tried this...in game mode it shows it works, they're at separate sorting layers but they still overlap?
Your answer
Follow this Question
Related Questions
Is there a way to mask out a sprite layer 0 Answers
I need my GameObject to Spawn in front of my sprites 2 Answers
How to avoid having clones on the same order in layer clip? 0 Answers
Scissor tool with 2d sprite 0 Answers
2D Games in Unity3D? 1 Answer