// Use this for initialization IEnumerator Start() { yield return(null); //GameObjectsToSort = FindGameObjectsWithLayer(SL); //GameObjectsToSort = FindGameObjectsWithObject(); LSOY = FindObjectsOfType <layerSortOnY>(); foreach (layerSortOnY LS in LSOY) { // if (LS.SortOnUpdate) { try { //GO.GetComponentInChildren<SpriteRenderer>().sortingOrder = Mathf.RoundToInt(transform.position.y * 100f) * -1; int idealOrder = Mathf.RoundToInt(LS.transform.position.y * 100f) * -1; LS.ReorderSprites(idealOrder); } catch { } //} } }
// Update is called once per frame void Update() { foreach (layerSortOnY LS in LSOY) { try { //GO.GetComponentInChildren<SpriteRenderer>().sortingOrder = Mathf.RoundToInt(transform.position.y * 100f) * -1; int idealOrder = Mathf.RoundToInt(LS.transform.position.y * 100f) * -1; LS.ReorderSprites(idealOrder); } catch { } } }