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

public class PickablesManager : MonoBehaviour {
    public static PickablesManager instance;

    public int count = 0;

    static public PickablesManager Get() {
        return(instance);
    }

    void Start() {
        instance = this;
    }

    void Update() {
        foreach(Pickable item in Pickable.GetList()) {
            if (UpdateCheck(item)) {
                break;
            }
        }
    }

    public bool UpdateCheck(Pickable currentItem) {
        List<Pickable> closeList = new List<Pickable>();
        closeList.Add(currentItem);

        foreach(Pickable item in Pickable.GetList()) {
            if (item == currentItem) {
                continue;
            }

            if (Vector2.Distance(currentItem.transform.position, item.transform.position) < 1) {
                closeList.Add(item);
            }
        }

        if (closeList.Count > 2) {
           
           
        
            foreach(Pickable item in closeList) {
                Destroy(item.gameObject);
            } 

            UnityEngine.Object pPrefab = Resources.Load("Prefabs/Nest");
            GameObject pNewObject = (GameObject)GameObject.Instantiate(pPrefab, currentItem.transform.position, Quaternion.Euler(0, 0, 0));
        


            return(true);
        }

        return(false);
    }
}

