ZSort.cs 491 Bytes
Newer Older
1 2 3 4 5 6
using UnityEngine;
using System.Collections;

public class ZSort : MonoBehaviour {

    private SpriteRenderer sr;
7
    public float offset = 0;
8 9 10 11 12

	void Start () {
        sr = GetComponent<SpriteRenderer>();
        if (sr) {
            sr.sortingLayerName = "Moving";
13
            offset += sr.sprite.bounds.extents.y;
14 15 16 17 18 19 20 21 22
        }
	}
	
	void LateUpdate () {
        if (sr) {
            sr.sortingOrder = (int)((transform.position.y - offset) * -100);
        }
	}
}