/// <summary>
        /// Gets a CollisionInteractable by specified tag.
        /// </summary>
        /// <param name="tag">The target CollisionInteractable tag.</param>
        /// <param name="isLast">If the target CollisionInteractable must be the last collision.</param>
        /// <returns>
        /// The collided CollisionInteractable or null if the conditions are not met.
        /// </returns>
        public CollisionInteractable CollisionWith(EInteractable tag, bool isLast)
        {
            if (isLast)
            {
                if (_collisionInteractables.Count == 0)
                {
                    return(null);
                }

                CollisionInteractable collisionInteractable =
                    _collisionInteractables[_collisionInteractables.Count - 1].transform.GetComponent <CollisionInteractable>();

                return(collisionInteractable.ContainsTag(tag)
                    ? _collisionInteractables[_collisionInteractables.Count - 1]
                    : null);
            }

            foreach (var collisionInteractable in _collisionInteractables)
            {
                if (collisionInteractable != null && collisionInteractable.ContainsTag(tag))
                {
                    return(collisionInteractable);
                }
            }

            return(null);
        }
        private void OnTriggerExit(Collider other)
        {
            if (other.attachedRigidbody == null)
            {
                return;
            }

            CollisionInteractable otherCollisionInteractable =
                other.attachedRigidbody.transform.GetComponent <CollisionInteractable>();

            if (_collisionInteractables.Contains(otherCollisionInteractable))
            {
                if (_colliderCounts[_collisionInteractables.IndexOf(otherCollisionInteractable)] > 1)
                {
                    _colliderCounts[_collisionInteractables.IndexOf(otherCollisionInteractable)]--;
                }
                else
                {
                    _colliderCounts.RemoveAt(_collisionInteractables.IndexOf(otherCollisionInteractable));
                    _collisionInteractables.Remove(otherCollisionInteractable);
                }
            }
        }
        private void OnTriggerEnter(Collider other)
        {
            if (other.attachedRigidbody == null)
            {
                return;
            }

            CollisionInteractable otherCollisionInteractable =
                other.attachedRigidbody.transform.GetComponent <CollisionInteractable>();

            if (otherCollisionInteractable != null)
            {
                if (!_collisionInteractables.Contains(otherCollisionInteractable))
                {
                    _collisionInteractables.Add(otherCollisionInteractable);
                    _colliderCounts.Add(1);
                }
                else
                {
                    _colliderCounts[_collisionInteractables.IndexOf(otherCollisionInteractable)] += 1;
                }
            }
        }
        /// <summary>
        /// Gets a CollisionInteractable by specified tag.
        /// </summary>
        /// <param name="target">The target CollisionInteractable.</param>
        /// <param name="isLast">If the target CollisionInteractable must be the last collision.</param>
        /// <returns>
        /// The target CollisionInteractable or null if the conditions are not met.
        /// </returns>
        public CollisionInteractable CollisionWith(CollisionInteractable target, bool isLast)
        {
            if (isLast)
            {
                if (_collisionInteractables.Count == 0)
                {
                    return(null);
                }
                return(_collisionInteractables[_collisionInteractables.Count - 1].transform == target.transform
                    ? _collisionInteractables[_collisionInteractables.Count - 1]
                    : null);
            }

            foreach (var collisionInteractable in _collisionInteractables)
            {
                if (collisionInteractable == target)
                {
                    return(collisionInteractable);
                }
            }

            return(null);
        }
 /// <summary>
 /// Removes tracking of a specified CollisionInteractable.
 /// </summary>
 /// <param name="otherCollisionInteractable">The CollisionInteractable to be removed.</param>
 public void RemoveCollision(CollisionInteractable otherCollisionInteractable)
 {
     _colliderCounts.RemoveAt(_collisionInteractables.IndexOf(otherCollisionInteractable));
     _collisionInteractables.Remove(otherCollisionInteractable);
 }