using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpriteOrderer : MonoBehaviour
{
    [SerializeField] bool m_movable = false;
    // Start is called before the first frame update
    [SerializeField]SpriteRenderer m_sr = null;
    [SerializeField] int m_offset = 0;
    void Start()
    {
        if(m_sr == null)
        {
            m_sr = GetComponent<SpriteRenderer>();
        }
        Sort();
        if (!m_movable)
        {
            Destroy(this);
        }
    }

    private void Update()
    {
        Sort();
    }


    void Sort()
    {
        m_sr.sortingOrder = Mathf.RoundToInt(transform.position.y * -1) + 
            /*Mathf.RoundToInt(transform.position.x * -0.5f)*/ + m_offset;
    }
}
