private void Update()
    {
        if (_canFire == false)
        {
            return;
        }
        // controller player dead
        AttackType attackType = AttackType.NONE;

        if (Input.GetMouseButton(0))
        {
            attackType  = attackType | AttackType.LEFT;
            attackType &= ~AttackType.NONE;
        }

        if (Input.GetMouseButton(1))
        {
            attackType  = attackType | AttackType.RIGHT;
            attackType &= ~AttackType.NONE;
        }

        _currentDelay += Time.deltaTime;
        if ((Input.GetMouseButton(0) || Input.GetMouseButton(1)) && _currentDelay >= _weaponDelay)
        {
            FireBullet(attackType);
            _recoilScript.AddRecoil();
            _cameraRecoil.AddRecoil(_muzzle.transform.right);
            AudioEffects._audioEffects.PlaySoundEffect(_weaponFireClip);
            _currentDelay = 0f;
        }
    }
Exemplo n.º 2
0
 private void Fire(float angle)
 {
     AudioEffects._audioEffects.PlaySoundEffect(_bulletSoundFX);
     _recoil.AddRecoil(transform.right);
     CameraFunctions._cameraFunctions.AddRecoil(transform.right);
     FireWeapon(angle);
     StartCoroutine("EmitMuzzleFlash");
     _weaponAmmo[_weaponType]--;
     OnAmmoChangeEvent();
 }
Exemplo n.º 3
0
    private void Update()
    {
        // get angle that you are pointing towards
        Vector3 target    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 direction = target - transform.position;
        float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        RotateWeapon(angle);

        _currentTimeBetweenShotFired += Time.deltaTime;

        // fire
        if (Input.GetMouseButtonDown(0) && _currentTimeBetweenShotFired >= _tapFireDelay || Input.GetMouseButton(0) && _currentTimeBetweenShotFired >= _fireDelay)
        {
            _audioSource.PlayOneShot(_weaponFiringClip);
            _cameraRecoilScript.AddRecoil(transform.right);
            _recoilScript.AddRecoil();
            EmitMuzzleFlash();
            FireWeapon(angle);
        }
    }
Exemplo n.º 4
0
 public void AddRecoil(Vector3 direction)
 {
     _recoil.AddRecoil(direction);
 }