Reputation: 33
I am new to unity and some concepts still eludes me.
I made an object with children (card) and made prefab, then I made variants and put them on the scene. Unfortunately the cards get messed up like on the picture. The children are in Default sorting layer and everyone of them has iterated number 1,2,3,4...
What am I making wrong if I want one card be over the second as separated object (with shadow and everything) and I intend to spam a lot of them (so I want to evade manually add or increase Z for each of them).
Also, it is not UI.
Thanks for help in advance
Upvotes: 3
Views: 2239
Reputation: 564
You can simply add a "Sorting Group" component to your Card prefab.
You should also create a new "Sorting Layer" for your Card.
Reference: https://docs.unity3d.com/Manual/class-SortingGroup.html
If you are looking to have dynamic text, "TEST TEST" or "5", for example, this becomes a little more complicated. I have had a lot of ordering issues using Prefabs with sprites and canvas/UI objects. I get unexpected behavior with "Sorting Group" in that scenario. I was able to solve this by adding a "Mesh Render" object with a "Text Mesh" component instead.
Upvotes: 3