예제 #1
0
        private void Update()
        {
            if (!_isFleeing)
            {
                return;
            }

            if (_isFleeing && !_wasRegistered)
            {
                if (_zone != null)
                {
                    _zone.Register(gameObject);
                    _wasRegistered = true;
                }
            }
            else if (!_isFleeing && _wasRegistered)
            {
                if (_zone != null)
                {
                    _zone.Unregister(gameObject);
                }
                _wasRegistered = false;
            }

            var isTooClose = Vector3.Distance(_threatPosition, transform.position) < AvoidDistance;

            if ((isTooClose && !_wasTooClose) ||
                _targetBlock == null ||
                (Vector3.Distance(_threatPosition, _targetPosition) < AvoidDistance))
            {
                findNewFleePosition(isTooClose);
            }

            _wasTooClose = isTooClose;
        }
예제 #2
0
        private void OnTriggerEnter(Collider other)
        {
            var zone = other.GetComponent <FleeZone>();

            if (zone != null)
            {
                if (_zone != null)
                {
                    _zone.Unregister(gameObject);
                }
                _zone = zone;

                if (_isFleeing)
                {
                    _zone.Register(gameObject);
                    _wasRegistered = true;
                }
            }
        }