- Home /
Nested sorting layers?
Hello, lets say i have an object that consist from gren sprite on the back and red on the front. And i wan to group them so sprites from one object would be rendered on top of another objects sprites. Right now i can do only this:
But i want this:
Is it possible?
sprite renderer has sorting layers? Are you using them?
I tried, but it looks like they are not a solution for my problem. I would need to create a new sorting layer for the each individual set of sprites. (i mean, the number of those green-red objects is unknown)
Answer by Derek-Wong · Feb 01, 2015 at 06:30 PM
I believed that Z-index is your friend. Assuming these are some objects that you will instantiate them repeatedly:
Public float spriteZ = 0.0f;
for(int i=0;i< numbersOfPrefabsYouWant; i++){
GameObject someObj = (GameObject)Instantiate(someObjPrefab);
someObj.transform.position = new Vector3(someX, someY, spriteZ);
spriteZ += 0.01f;
}
You should also set the z-index on the Green and Red sprite, say if want red on top, red's Z should be smaller than Green's Z.
Hope it helps.
This really works with sorting layers and I am using this solution myself, I will show you how to do it in detail tomorrow if you still cannot do it.