Change order Layer of sorting Group by Script

Hi everybody ! I’m doing a 2d game and before , i used a simple script to change the order or layer to make a fake perspective.

But today i’m doing a harder animation with “bones system” , so i use a Sorting group in my player object wich contain his “body”. But like this, my fake perspective don’t work anymore :confused:

so i want to know if there is a way to change the order in layer of a sorting group ?

Here my script :

void Update () {
        GetComponent<SpriteRenderer>().sortingOrder = Mathf.RoundToInt(transform.position.y * 100f) * -1;

    }

If someone know how can i do that i’ll really appreciate ! :slight_smile:

Have a good day and thx !

Up

Well…

As you discovered, it can be tricky to mix 2D and 3D objects while using sorting layers. I find sorting layers don’t work well at all for that purpose.

I ended up using multiple cameras that cull different layers (regular layers, not sorting layers), and it’s pretty easy to set their priority order. The first camera clears to skybox, and the other cameras clear by depth only.

Thanks for you’re help!
I’m doing a 2d game on android and if i use multiple camera, i have some trouble with the FPS…

there is no other way to do this simple perspective ? Like make indepedant the body of my player like sorting group do, and keep control of the layer position of my main object ?. or other thing like that ? :confused:

EDIT : I find a simple way to do this!

Go to “Edit” > “Project settings” > “Graphics”

And in the GrapficsSetting, in the section “Camera settings” , select “Custom Axis” and put : X 0 / Y 1 / Z 0

Know the perpective is just perfect and work with Sorting group !