Пример #1
0
    private void RaycastFire()
    {
        float spreadRatio = _advancedSettings.spreadAngle / Camera.main.fieldOfView;

        Vector3 spread = spreadRatio * Random.insideUnitCircle;

        Ray ray = Camera.main.ViewportPointToRay(Vector3.one * .5f + spread);

        if (Physics.Raycast(ray, out RaycastHit hitInfo, float.MaxValue))
        {
            //Spawn Bullet Impact
            _vfxController.SpawnImpactHitVFX(hitInfo.point, hitInfo.normal);

            //Play impact sound
            _sfxController.PlaySFXSource(_bulletImpactClip, hitInfo.point, hitInfo.normal);

            //Check if hit enemy
            if (hitInfo.collider.gameObject.layer == 10)
            {
                hitInfo.collider.GetComponent <TargetComponent>().TakeHit(_damage);
            }
        }

        //Spawn Bullet Trail
        _vfxController.SpawnBulletTrailVFX(GetMuzzleEndPosition(_cameraController.GetMainCamera(), _cameraController.GetWeaponCamera()), hitInfo.point);
    }
Пример #2
0
 private void PlaySound()
 {
     if (hitClips.Length > 0 && _sFXController)
     {
         AudioClip clip = hitClips[Random.Range(0, hitClips.Length)];
         _sFXController.PlaySFXSource(clip, transform.position, transform.forward);
     }
 }