Hello - I am new to Unity, and I am trying to make a 2D, top-down, isometrical game. I am wondering how I can sort the layer of objects based on their position of the Y axis using a script. In other words, I am trying to create the effect of a background/foreground according to Y position. For example, if object_1 is beneath object_2, the layer for object_1 should be greater than the layer for object_2.
If anyone can help me, I would greatly appreciate it. Thanks!
Use Transparency Sort Mode on a Camera. You can conveniently set a custom axis project wide to sort based on Y axis instead of Z, mix with Sorting Groups to keep a whole character made of multiple sprites together and sort as a single entity.
Instead, in Assets create new asset of type Renderer 2D Data (Create/Rendering/Universal Render Pipeline/2D Renderer), configure transparency in it’s inspector and then use it as a default renderer in yout URP object.