- Home /
Z order for GameObject
Unity native 2d proved a method to oder SPRITES in render depth by "sorting layer" and "order in layer" it is good enough for only one game object but if I have two game objects, they have the same sprites structure becouse they are cloned from same prefab, problem comes: how can I get the right result if one game object is overlaped by another?
eg: in prefab, 'A' sprite overlay 'B' sprite. game object 'a' and game object 'b' are both cloned from this prefab. I placed game object 'a' in front of game object 'b'(meanes 'a' have a minor z), so I expected 'a' overlay 'b' totally, but sprite 'b-A' overlaied 'a-B', in spite of the z order of game objects.
Order In Layer The overlay priority of this sprite within its layer. Lower numbers are rendered first and subsequent numbers overlay those below.
Change the order in the layer right after you have added the 2nd sprite to the game.
What is considered closer to the camera is up to you. I imagine comparing y values could be used in some 2D games to deter$$anonymous$$e what should be drawn as closer to the camera.
What kind of 2D game is it?
a game of characters fight in a battle ground, 3 vs. 3, attack in turn, characters lower on screen is nearer to the camera. so comparing y value is a good way, but I have 50 parts with 50 sprites for one character, I must have a nice try to see if there is a performance problem.
thank you for the answer~~
changing sortingOrder dynamicly is low efficent. my character will run on the battleground, so I have to caulculate it all the time. on my phone(Samsun 9082), Camera.Render cost 40ms+, framerate dorp to about 20, which is not acceptable
Your answer
Follow this Question
Related Questions
Sprite quality decreased after adding 3d object to 2d game 0 Answers
How to mask sprites in 4.3? 2 Answers
Sprite Editor won't create files. 2 Answers
Rotating Produces Odd Results [Unity 2D] 1 Answer
2d sprite animation issue 2 Answers