Since this was one of the major results when googling a similar problem, I figure I'd link to my solution based on this answer.
http://forum.unity3d.com/threads/order-in-layer-16-bit-limit-huge-world-in-one-scene.331646/
Order In Layer is 16 bits, so OrderInLayer = Position.Z is limited to 32767,32767.
Unity gives a floating point limitation warning after 99999, which is a little more than 3x the OrderInLayer limitations.
The solution? Divide by 3!
If you change Order In Layer every 3 integers/position instead of every 1, it is really closer to the floating point limitation for positions (32767 * 3 = almost 99999). I tested this by changing Order In Layer every 5, and I didn't notice any difference in my game. (1 position = 1 pixel). It's a 3D world with 2D sprites and a perspective camera, so this was not easy after trying so many solutions. I tried other solutions as you can see in the thread (and more that I didn't mention in the thread.)
Anyway, here is the code:
int pos = Mathf.RoundToInt(theParent.transform.position.z);
pos /= 3;
spriteRenderer.sortingOrder = (pos * -1) + OrderOffset;
↧