Example #1
0
        /// <summary>
        /// Check to see if agents heard a sound form this audio source.
        /// </summary>
        /// <param name="noticability">A value between 0 and 1 that represents how noticable a sound is. 0 means no agents will notice it without some other means of awareness. 1 means almost all agents within range will notice it.</param>
        private IEnumerator NotifyOfSound(float noticability)
        {
            isNotifyingOfSound = true;

            float range     = 30;
            int   maxAgents = 200;

            Collider[] agentColliders = new Collider[maxAgents];
            int        numOfAgents    = Physics.OverlapSphereNonAlloc(transform.position, range, agentColliders, PhysicsFilter.LayerFilter.CharacterControllers);

            for (int i = 0; i < numOfAgents; i++)
            {
                AiBaseCharacter character = agentColliders[i].GetComponent <AiBaseCharacter>();
                if (character != null && character != m_Self)
                {
                    character.hearSound(transform, noticability);
                }
                yield return(new WaitForEndOfFrame());
            }

            isNotifyingOfSound = false;
        }
Example #2
0
 private void Awake()
 {
     m_Self = GetComponentInParent <AiBaseCharacter>();
 }