// OnTriggerEnter is called when the GameObject collides with another GameObject private void OnTriggerEnter(Collider other) { // If detected object has matching tag, add it if (other.gameObject.HasTag(DetectedTags.ObjectTags) && !DetectedColliders.Contains(other)) { DetectedColliders.Add(other); } }
protected virtual GameObject AddCollider(Collider c) { GameObject newColliderDetection = null; GameObject newRigidBodyDetection = null; if (AddColliderToMap(c, c.gameObject, _gameObjectColliders)) { DisposeRayCastTarget(c.gameObject); newColliderDetection = c.gameObject; } if (c.attachedRigidbody != null && AddColliderToMap(c, c.attachedRigidbody.gameObject, _rigidBodyColliders)) { DisposeRayCastTarget(c.attachedRigidbody.gameObject); newRigidBodyDetection = c.attachedRigidbody.gameObject; } var newDetection = DetectionMode == SensorMode.Colliders ? newColliderDetection : newRigidBodyDetection; if (ShouldIgnore(newDetection)) { return(null); } if (RequiresLineOfSight && newDetection != null) { bool prevDetected = _objectVisibility.ContainsKey(newDetection) && _objectVisibility[newDetection] >= _minimumVisibility; _objectVisibility[newDetection] = TestObjectVisibility(newDetection); if (!prevDetected && _objectVisibility[newDetection] >= _minimumVisibility) { if (!DetectedColliders.Contains(c)) { DetectedColliders.Add(c); } return(newDetection); } return(null); } if (!DetectedColliders.Contains(c)) { DetectedColliders.Add(c); } return(newDetection); }