Esempio n. 1
0
    void Fire()
    {
        if (_bullets == 0)
        {
            // play clicking noise?
            return;
        }
        _weapon.SetFloat(HitscanGun.BulletsIndex, _bullets - 1);

        if (!silenced)
        {
            _chadistAI.SpotPlayer(transform.position);
        }

        Ray shotRay = new Ray(_weapon.cam.transform.position, _weapon.cam.transform.rotation * Vector3.forward);

        if (Physics.Raycast(shotRay, out RaycastHit hit, Mathf.Infinity, layerMask))
        {
            // we hit something???
            Transform hitObject = hit.transform;
            Rigidbody hitRB     = hitObject.GetComponent <Rigidbody>();
            if (hitRB)
            {
                hitRB.AddForceAtPosition(shotRay.direction * kineticPower, hit.point);
            }

            Damageable damageable = hitObject.GetComponent <Damageable>();
            if (damageable)
            {
                damageable.Shoot(new PlayerShotInfo(_weapon.playerInventory, _weapon, damage, hit, shotRay.direction));
                if (damageable.fxPrefab)
                {
                    SpawnHitFX(damageable.fxPrefab, hit);
                }
                else
                {
                    SpawnHitFX(defaultHitPrefab, hit);
                }
            }
            else
            {
                // spawn fx
                SpawnHitFX(defaultHitPrefab, hit);
            }
        }

        _kickController.AddVel(_weapon.cam.transform.TransformVector(Vector3.forward * (-kickBack)));
        _kickController.AddKick(Quaternion.Euler(-kickRotation, 0, 0));

        _lastShot = Time.time;
        animator.SetTrigger("fire");
    }
 private void OnMelee(float damage)
 {
     _chadistAI.SpotPlayer(_player.transform.position);
 }