// OnTriggerExit is called when the Collider other has stopped touching the trigger private void OnTriggerExit(Collider other) { // Remove detected object when leaving if (detectedColliders.Contains(other)) { DetectedColliders.Remove(other); // Do some actions if the nearest object gets removed if (nearestCollider == other) { // Disable outline on remove from list if (nearestCollider.gameObject.HasTag("Outline")) { nearestCollider.GetComponentInChildren <TDS_DiffuseOutline>().DisableOutline(); } } // Desactivate feedback if needed if (detectedColliders.Count == 0) { nearestCollider = null; // Desactivate feedback if (interactText.gameObject.activeInHierarchy) { interactText.gameObject.SetActive(false); } } } }
protected virtual GameObject RemoveCollider(Collider c) { if (c == null) { ClearDestroyedGameObjects(); return(null); } GameObject colliderDetectionLost = null; GameObject rigidBodyDetectionLost = null; if (RemoveColliderFromMap(c, c.gameObject, _gameObjectColliders)) { DisposeRayCastTarget(c.gameObject); colliderDetectionLost = c.gameObject; } if (c.attachedRigidbody != null && RemoveColliderFromMap(c, c.attachedRigidbody.gameObject, _rigidBodyColliders)) { DisposeRayCastTarget(c.attachedRigidbody.gameObject); rigidBodyDetectionLost = c.attachedRigidbody.gameObject; } var detectionLost = DetectionMode == SensorMode.Colliders ? colliderDetectionLost : rigidBodyDetectionLost; if (ShouldIgnore(detectionLost)) { return(null); } DetectedColliders.Remove(c); if (RequiresLineOfSight && detectionLost != null) { if (_objectVisibility.ContainsKey(detectionLost)) { _objectVisibility.Remove(detectionLost); return(detectionLost); } return(null); } if (detectionLost != null) { _objectVisibility.Remove(detectionLost); } return(detectionLost); }
/// <summary> /// Clears colliders from the detected colliders list that are disables. /// </summary> private void OrderObjects() { // If not enabled or not detecting anything, return if (detectedColliders.Count == 0) { // Desactivate feedback if needed if (interactText.gameObject.activeInHierarchy) { interactText.gameObject.SetActive(false); } return; } // Get element(s) to remove Collider[] _toRemove = new List <Collider>(detectedColliders).Where(d => (d == null) || (d.enabled == false)).ToArray(); if (_toRemove.Length > 0) { // Remove all disable colliders foreach (Collider _collider in _toRemove) { DetectedColliders.Remove(_collider); // Do some actions if the nearest object gets removed from list if (nearestCollider == _collider) { // Disable outline on remove from list if ((_collider != null) && nearestCollider.gameObject.HasTag("Outline")) { nearestCollider.GetComponentInChildren <TDS_DiffuseOutline>().DisableOutline(); } } } } // Order objects if (detectedColliders.Count > 0) { Vector2 _pos = new Vector2(transform.position.x, transform.position.z); detectedColliders = detectedColliders.OrderBy(c => Mathf.Abs((_pos - new Vector2(c.transform.position.x, c.transform.position.z)).magnitude)).ToList(); // Set nearest collider if different if (nearestCollider != detectedColliders[0]) { // Disable outline if (nearestCollider && nearestCollider.gameObject.HasTag("Outline")) { nearestCollider.GetComponentInChildren <TDS_DiffuseOutline>().DisableOutline(); } nearestCollider = detectedColliders[0]; // If feedback should be displayed, display it if (doDisplayFeedback && !interactText.gameObject.activeInHierarchy) { interactText.gameObject.SetActive(true); } // If the object has outline tag, activate the outline on it if (doDisplayFeedback && nearestCollider.gameObject.HasTag("Outline")) { nearestCollider.GetComponentInChildren <TDS_DiffuseOutline>().EnableOutline(); } } } // Desactivate feedback if needed else if (interactText.gameObject.activeInHierarchy) { interactText.gameObject.SetActive(false); } }