コード例 #1
0
    public void HeardGameObject(NoiseActuator Other, float OtherNoiseRadius, float AlertFactor)
    {
        // Do nothing if I heard myself make noise ...
        if (Other == null)
        {
            return;
        }                             // == Owner.NoiseActuator) { return; }

        if (Other == null || Head == null)
        {
            return;
        }
        if (Other.Owner == null || Head.transform == null)
        {
            return;
        }

        Vector3 HeadToOther = Other.Owner.position - Head.transform.position;
        float   DistToOther = HeadToOther.magnitude;

        if (DistToOther <= HearingRadius + OtherNoiseRadius)
        {
            if (WhenObjectHeard != null)
            {
                WhenObjectHeard(Other, AlertFactor);
                return;
            }

            Debug.LogWarning("SoundSensor::HeardGameObject::No 'WhenObjectHeard' callback has been set!");
        }
    }
コード例 #2
0
    //private Animal.AnimalBase Owner;
    #endregion

    //-----------------------------------------------------------------------------------------------------------

    public void Init(Transform HeadJoint)//, Animal.AnimalBase Owner)
    {
        //this.Owner = Owner;
        if (Head == null)
        {
            Head = HeadJoint;
        }

        // Each sound sensor will subscribe to the global make noise event.
        // This way, when a noise is made every sound sensor will check if it heard the noise ...
        NoiseActuator.AddListener(HeardGameObject);
    }