Esempio n. 1
0
        /// <summary>
        /// Action that takes place when an object enters our trigger
        /// </summary>
        private void OnTriggerExit(Collider other)
        {
            /// Check if the collision has the AwarenessTarget component
            if (!other.TryGetComponent <AwarenessTarget>(out AwarenessTarget target))
            {
                return;
            }

            if (target == this.currTarget)
            {
                ResetLookDirection();
                this.currTarget = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Action that takes place when an object is inside our trigger
        /// </summary>
        private void OnTriggerStay(Collider other)
        {
            /// Check if the collision has the AwarenessTarget component
            if (!other.TryGetComponent <AwarenessTarget>(out AwarenessTarget newTarget))
            {
                return;
            }

            /// If we don't have a target yet
            if (this.currTarget == null)
            {
                this.currTarget = newTarget;
            }
            else
            {
                if (!CanSee(newTarget.transform))
                {
                    return;
                }

                /// If we find some object with higher priority
                if (newTarget.Priority > this.currTarget.Priority)
                {
                    this.currTarget = newTarget;
                }
                else if (newTarget.Priority == this.currTarget.Priority)
                {
                    /// If they have the same priority, set the closest as the target
                    float targetDist = Vector3.Distance(this.transform.position, this.currTarget.transform.position);
                    float newDist    = Vector3.Distance(this.transform.position, newTarget.transform.position);

                    /// If we are closer to the new object we set this as our target
                    if (newDist > targetDist)
                    {
                        this.currTarget = newTarget;
                    }
                }
            }
        }