ZSort.cs 469 Bytes
Newer Older
Luke Smith's avatar
Luke Smith committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
using UnityEngine;
using System.Collections;

public class ZSort : MonoBehaviour {

    private SpriteRenderer sr;
    public float offset = 0;

	void Start () {
        sr = GetComponent<SpriteRenderer>();
        if (sr) {
            sr.sortingLayerName = "Moving";
            offset += sr.sprite.bounds.extents.y;
        }
	}
	
	void LateUpdate () {
        if (sr) {
            sr.sortingOrder = (int)((transform.position.y - offset) * -100);
        }
	}
}