I have a simple script that sorts the sprite renderer layers after their z position. The only problem is that when there are multiple sprites on the same z axis the layering flips out because they get the same sorting layer. Here is my code: `using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class SpriteSorting : MonoBehaviour
{
[SerializeField] float spriteTransform;
[SerializeField] int spriteOrder;
Vector3 spritePos;
GameObject cam;
void Update()
{
//global transform position determines sorting layer:
spriteTransform = this.transform.position.z;
spriteOrder = (int)spriteTransform;
this.gameObject.GetComponent<SpriteRenderer>().sortingOrder = spriteOrder;
}
}`

