public void ScanForObjects(CandiceDetectionRequest request) { Vector3 center = transform.position; bool is3D = request.is3D; float radius = request.radius; float height = request.height; float lineOfSight = request.lineOfSight; SensorType type = request.type; //Array that will store all collided objects //Collider[] hitColliders = Physics.OverlapSphere(center, radius); Vector3 halfExtents = new Vector3(radius, height, radius); Collider[] hitColliders = null; if (type == SensorType.Sphere) { hitColliders = Physics.OverlapSphere(center, radius); } Dictionary <string, List <GameObject> > detectedObjects = new Dictionary <string, List <GameObject> >(); //Loop though each object foreach (Collider collider in hitColliders) { GameObject go = collider.gameObject; float distance = Vector3.Distance(center, go.transform.position); float angle = Vector3.Angle(go.transform.position - center, transform.forward); if (angle <= lineOfSight / 2) { CompareTags(go, request.detectionTags, ref detectedObjects); } } objectDetectedCallback(new CandiceDetectionResults(detectedObjects)); }