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

public class ObjectCheck : MonoBehaviour
{
    public string neededObject;

    public bool correct;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
            if (transform.childCount > 0)
            {
            if (GetComponentInChildren<PointAndClick>().affectedBySupport == false)
            {
                if (GetComponentInChildren<PointAndClick>().objectName == neededObject)
                {
                    correct = true;
                    if (gameObject.tag == "Ground")
                    {
                        GetComponent<PolygonCollider2D>().enabled = true;
                    }
                }

            }
            else if (GetComponentInChildren<PointAndClick>().affectedBySupport == true)
            {
                if (gameObject.tag == "Ground" && GetComponentInChildren<PointAndClick>().affetctedSupportSnap.GetComponent<ObjectCheck>().correct == false)
                {
                    GetComponent<PolygonCollider2D>().enabled = false;
                }
                else
                {
                    GetComponent<PolygonCollider2D>().enabled = true;
                }
            }

        } else
            {
                correct = false;

            if (gameObject.tag == "Ground")
            {
                GetComponent<PolygonCollider2D>().enabled = false;
            }
            
        }

    }

}
