コード例 #1
0
    //  Set Location Of Interest.
    private void ScanForTargets()
    {
        lastDetectionCount = detectionCount;

        colliders = Physics.OverlapSphere(npc.transform.position, npc.sightRange, npc.myEnemyLayers);

        foreach (Collider col in colliders)
        {
            RaycastHit hit;
            Transform  target = col.transform;
            npcSight.VisibilityCalculations(target);

            if (npcSight.angleBetweenNpcAndPlayer < npc.viewAngle / 2f)
            {
                if (Physics.Linecast(npcSight.headPosition, npcSight.targetPosition, out hit, npc.mySightLayers))
                {
                    foreach (string tags in npc.myEnemyTags)
                    {
                        if (hit.transform.CompareTag(tags))
                        {
                            detectionCount++;
                            npc.possibleTarget = col.transform;
                            break;
                        }
                    }
                }
            }
        }

        //  Check if detection count has changed and if not than set it back to 0.
        if (detectionCount == lastDetectionCount)
        {
            detectionCount = 0;
        }

        //  Check if detection count is greater than the requirement and if so pursue.
        if (detectionCount >= npc.requiredDetectionCount)
        {
            detectionCount = 0;
            npc.SetLocationOfInterest(npc.possibleTarget.position, true);
            npc.pursueTarget = npc.possibleTarget.root;

            InformNearbyAllies();
            ToPursueState();
        }

        GoToLocationOfInterest(npc.locationOfInterest);
    }
コード例 #2
0
 void AlertStateActions(Transform target)
 {
     npc.SetLocationOfInterest(target.position, true);
     ToAlertState();
 }