public GameObject Hear() { // If the target object is null then determine if there are any objects within hearing range based on the layer mask if (targetObject == null) { if (usePhysics2D) { returnedObject = MovementUtility.WithinHearingRange2D(transform, offset, audibilityThreshold, hearingRadius, objectLayerMask); } else { returnedObject = MovementUtility.WithinHearingRange(transform, offset, audibilityThreshold, hearingRadius, objectLayerMask); } } else { GameObject target = null; if (!string.IsNullOrEmpty(targetTag) && !targetTag.Contains("Untagged")) { target = GameObject.FindGameObjectWithTag(targetTag); } else { target = targetObject; } if (target == null) { target = targetObject; } if (Vector3.Distance(target.transform.position, transform.position) < hearingRadius) { returnedObject = MovementUtility.WithinHearingRange(transform, offset, audibilityThreshold, targetObject); } } if (returnedObject != null) { return(returnedObject); } else { return(null); } }