Пример #1
0
    void FixedUpdate()
    {
        if (!_isMasterClient || null == _weapon)
        {
            return;
        }
        RaycastHit hit;

        if (_lockTimer > 0)
        {
            _canShoot = HasHit(_bot.ShootPoint.position, _bot.ShootPoint.forward, _weapon.FireRange, out hit);
            if (_canShoot)
            {
                _lockTimer = GameSetting.Instance.Bot.LockTime;
            }
            else if (_shootTimer <= 0)
            {
                _shootTimer = _weapon.FireRate * Random.Range(0.1f, 0.9f);
            }
        }
        else
        {
            var data  = GameSetting.Instance.Bot;
            var angle = data.ScanAngle / data.ScanLine;
            for (int i = 0; i < data.ScanLine; i++)
            {
                var y         = angle * i + Mathf.Repeat(angle * Time.time, angle) - data.ScanAngle * 0.5f;
                var direction = _bot.ShootPoint.rotation * Quaternion.Euler(0, y, 0) * Vector3.forward;
                if (HasHit(_bot.ShootPoint.position, direction, _weapon.FireRange, out hit))
                {
                    _bot.Lock(hit.transform.root.GetChild(0));
                    _lockTimer  = data.LockTime;
                    _shootTimer = _weapon.FireRate;
                    break;
                }
            }
        }
    }