Esempio n. 1
0
    void Attack()
    {
        if (Time.time - _lastAttackTime > _attackInterval)
        {
            Bounds  targetBounds    = _target.collider.bounds;
            Vector3 attackablePoint = targetBounds.center;
            attackablePoint.y += (targetBounds.size.y / 4.0f);

            //создаем и выпускаем стрелу по направлению к врагу
            var forward = attackablePoint - _arrowStartPoint.position;

            Quaternion rotationAttack;
            if (forward != Vector3.zero)
            {
                rotationAttack = Quaternion.LookRotation(forward);
            }
            else
            {
                rotationAttack = Quaternion.Euler(Vector3.zero);
            }
            Vector3 dirAttack = forward.normalized;

            GameObjectManager.CreateArrow(_arrowPrefab, _arrowStartPoint.position, rotationAttack,
                                          BulletLayer, dirAttack * _arrowSpeed, EnemyLayerMask, _damage);

            _lastAttackTime = Time.time;
        }
    }