using UnityEngine;

namespace RebootKit.Engine.Simulation.Sensors {
    public class RaycastSensor : ISensor {
        public LayerMask layerMask;
        public float maxDistance;
        public Ray ray;

        public bool HasHit { get; private set; }
        public RaycastHit Hit { get; private set; }

        public GameObject Sense() {
            HasHit = Physics.Raycast(ray, out RaycastHit hit, maxDistance, layerMask);

            if (HasHit) {
                Hit = hit;
                return Hit.transform.gameObject;
            }

            Hit = default;
            return null;
        }

        public void Clear() {
            HasHit = false;
            Hit = default;
        }
    }
}