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

public class Sight : MonoBehaviour
{
    [SerializeField] float sightDistance = 3f;
    [SerializeField] LayerMask targetLayerMask = Physics.DefaultRaycastLayers;
    [SerializeField] string[] targetTags = { "Player", "Plant" };

    public List<Collider2D> collidersInSight = null;

    void Update()
    {
        Collider2D[] collidersInBox =
        Physics2D.OverlapCircleAll(
            transform.position,
            sightDistance,
            targetLayerMask);

        collidersInSight.Clear();

        foreach (Collider2D c in collidersInBox)
        {
            if (targetTags.Contains(c.tag))
            {
                collidersInSight.Add(c);
            }
        }
    }

    void OnDrawGizmos()
    {
        Gizmos.color = Color.magenta;
        Gizmos.DrawWireSphere(transform.position, sightDistance);
    }
}
