Change Soring Layer OnCollisionEnter2D

Is it possible to change a SpriteLayer when the Player enters a BoxCollider2D?
As the image show. The Player is on Default Sorting Layer 0, the ramp is Default Sorting Layer 10.
Which means the player can walk behind the ramp, but if he walks around the corner and want to enter the ramp, I want the ramp to move down to Default Sorting Layer -1, so the player is appears on top of it.
If that makes sense? (Image attached)

Is this possible or does anyone have another suggestion?

If you start with the documentation for SpriteRenderer you will notice properties you can manipulate related to sorting.

1 Like