Exemplo n.º 1
0
 public GameObject NotSee()
 {
     if (usePhysics2D)
     {
         // If the target object is null then determine if there are any objects within sight based on the layer mask
         if (targetObject == null)
         {
             returnedObject = MovementUtility.WithinSight2D(transform, offset, fieldOfViewAngle, viewDistance, -1, targetOffset, angleOffset2D, ignoreLayerMask);
         }
         else
         { // If the target is not null then determine if that object is within sight
             returnedObject = MovementUtility.WithinSight2D(transform, offset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, angleOffset2D, ignoreLayerMask);
         }
     }
     else
     {
         // If the target object is null then determine if there are any objects within sight based on the layer mask
         if (targetObject == null)
         {
             returnedObject = MovementUtility.WithinSight(transform, offset, fieldOfViewAngle, viewDistance, -1, targetOffset, ignoreLayerMask);
         }
         else
         { // If the target is not null then determine if that object is within sight
             returnedObject = MovementUtility.WithinSight(transform, offset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, ignoreLayerMask);
         }
     }
     if (returnedObject == null)
     {
         return(returnedObject);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
 public GameObject CanSee()
 {
     if (usePhysics2D)
     {
         // If the target object is null then determine if there are any objects within sight based on the layer mask
         if (targetObject == null)
         {
             returnedObject = MovementUtility.WithinSight2D(transform, offset, fieldOfViewAngle, viewDistance, objectLayerMask, targetOffset, angleOffset2D, ignoreLayerMask);
         }
         else // If the target is not null then determine if that object is within sight
         {
             returnedObject = MovementUtility.WithinSight2D(transform, offset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, angleOffset2D, ignoreLayerMask);
         }
     }
     else
     {
         // If the target object is null then determine if there are any objects within sight based on the layer mask
         if (targetObject == null)
         {
             returnedObject = MovementUtility.WithinSight(transform, offset, fieldOfViewAngle, viewDistance, objectLayerMask, targetOffset, ignoreLayerMask);
         }
         else // If the target is not null then determine if that object is within sight
         {
             returnedObject = MovementUtility.WithinSight(transform, offset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, ignoreLayerMask);
         }
     }
     if (returnedObject != null)
     {
         // Return success if an object was found
         return(returnedObject);
     }
     // An object is not within sight so return failure
     return(null);
 }
Exemplo n.º 3
0
        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);
            }
        }