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

public class Y2DSorter : MonoBehaviour {
    [SerializeField] Transform target;
    [SerializeField] Y2DSorterData data;
    [SerializeField] Transform shadowTarget;
    Transform transf;

    public float height = 0.0f;

    private void Awake() {
        transf = GetComponent<Transform>();
        if(data.oneTimeOnly) {
            Sort();
            enabled = false;
        }
        
    }

    static Vector3 buf;
    static float heightBuf;

    private void Update() {
        Sort();
    } 

    void Sort() {
        if(data.to2D) transf.position = data.To2D(target);
        else transf.position = data.To3D(height,target);

        if(shadowTarget != null) {
            shadowTarget.position = data.To2DShadow(target);
        } 

    }
}
