Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        // If we need to do another check, then do the check!
        if (Time.time >= nextCheckTime)
        {
            nextCheckTime = Time.time + checkFrequencySeconds;

            List <TargetInformation> visibleCharacterColliders = new List <TargetInformation>();
            // Find all colliders in the character layer that are within the search radius of us!
            foreach (Collider potentialTarget in Physics.OverlapSphere(transform.position, maxVisionDistance, characterLayerMask, QueryTriggerInteraction.Ignore))
            {
                if (!selfColliders.Contains(potentialTarget))
                {
                    TargetInformation data = CalculateTargetInfo(potentialTarget);
                    if (data != null)
                    {
                        visibleCharacterColliders.Add(data);
                    }
                }
            }

            // Notify interested parties of the update!
            // DebuggingHelpers.Log("I am the ICharacterDetector and i am sending a vision update, sending " + visibleCharacterColliders.Count + " possible colliders to check");
            VisionUpdatedEvent?.Invoke(this, visibleCharacterColliders.AsReadOnly());
        }
    }
    // Update is called once per frame
    void Update()
    {
        // If we need to do another check, then do the check!
        if (Time.time >= nextCheckTime)
        {
            nextCheckTime = Time.time + checkFrequencySeconds;

            List <TargetInformation> visibleCharacterColliders = new List <TargetInformation>();
            // Find all colliders in the character layer that are within the search radius of us!
            foreach (Collider potentialTarget in Physics.OverlapSphere(transform.position, maxVisionDistance, characterLayerMask, QueryTriggerInteraction.Ignore))
            {
                if (!selfColliders.Contains(potentialTarget) && CanSee(potentialTarget))
                {
                    visibleCharacterColliders.Add(new TargetInformation(potentialTarget, potentialTarget.bounds.center));
                }
            }

            // Notify interested parties of the update!
            VisionUpdatedEvent?.Invoke(this, visibleCharacterColliders);
        }
    }