コード例 #1
0
        protected virtual void OnTriggerStay(Collider other)
        {
            SensorTarget foundTarget = other.GetComponent <SensorTarget>();

            if (foundTarget)
            {
                Alert(foundTarget.associatedPawn);
            }
        }
コード例 #2
0
        protected virtual void OnCollisionStay(Collision collision)
        {
            SensorTarget foundTarget = collision.transform.GetComponent <SensorTarget>();

            if (foundTarget)
            {
                Alert(foundTarget.associatedPawn);
            }
        }
コード例 #3
0
        protected virtual void FixedUpdate()
        {
            Collider[] foundCols = Physics.OverlapSphere(transform.position, visionDistance, layersToCheck);

            foreach (Collider c in foundCols)
            {
                SensorTarget target = c.GetComponent <SensorTarget>();

                if (target)
                {
                    Vector3 vecToTarget = c.transform.position - transform.position;
                    if (Vector3.Angle(transform.forward, vecToTarget) <= fieldOfView * 0.5f)
                    {
                        int obstacleCount = Physics.RaycastAll(transform.position, vecToTarget, visionDistance, layersToCheck, QueryTriggerInteraction.Ignore).Length;
                        //Debug.Log("Obstacles to possible target " + target.name + ": " + obstacleCount);
                        if (obstacleCount <= 1)
                        {
                            //If we have gotten this far, then the target is within the sight sensor
                            Alert(target.associatedPawn);
                        }
                    }
                }
            }
        }