예제 #1
0
        private void OnTriggerStay2D(Collider2D collision)
        {
            if (!collision.attachedRigidbody)
            {
                return;
            }

            PerceiveUnit unit = collision.GetComponent <PerceiveUnit>();

            if (!unit)
            {
                return;
            }

            _noiseAccumulator += collision.attachedRigidbody.velocity.magnitude * walkVelocityScale;

            if (_noiseAccumulator > noiseThreshold && SenseNoise.CanSpreadNoise())
            {
                _noiseAccumulator = 0;

                NoiseData noiseData = new NoiseData();
                noiseData.position = collision.transform.position;
                noiseData.velocity = collision.attachedRigidbody.velocity;
                noiseData.fraction = unit.fraction;

                SenseNoise.SpreadNoise(noiseData);
            }
        }
예제 #2
0
        void Start()
        {
            var healthController = GetComponent <HealthController>();

            healthController.onDamageCallback += (DamageData data) =>
            {
                _damageAccumulator += data.damage;

                if (_damageAccumulator >= damageThreshold && SenseNoise.CanSpreadNoise())
                {
                    _damageAccumulator = 0;

                    NoiseData noiseData = new NoiseData();
                    noiseData.position = data.position;
                    noiseData.velocity = Vector2.zero;

                    SenseNoise.SpreadNoise(noiseData);
                }
            };
        }