コード例 #1
0
    private void Shoot()
    {
        currentAmmo--;
        var index = Random.Range(0, shootingClips.Length);

        audioSource.clip = shootingClips[index];
        audioSource.Play();
        if (!fpAnimator.GetCurrentAnimatorStateInfo(0).IsTag(ZOOM) &&
            !fpAnimator.GetCurrentAnimatorStateInfo(0).IsTag(ZOOM_OUT))
        {
            fpAnimator.SetTrigger(SHOOT);
            CmdOnShoot();
        }

        if (!fpAnimator.GetCurrentAnimatorStateInfo(0).IsTag(ZOOM))
        {
            recoilScript.RecoilFire();
        }
        else
        {
            recoilScript.RecoilFireZoom();
        }

        if (!isLocalPlayer)
        {
            return;
        }

        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit))
        {
            if (hit.collider.CompareTag("Player"))
            {
                CmdPlayerShot(hit.collider.name, weapon.damage);
                HitActive();
                Invoke(nameof(HitDisable), hitmarkerDuration);
            }

            if (!hit.collider.CompareTag("Ceiling") && !hit.collider.CompareTag("Health") &&
                !hit.collider.CompareTag("Ammo") &&
                !hit.collider.CompareTag("Dead"))
            {
                var ImpactGO = Instantiate(hitEffect, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(ImpactGO, 3f);
            }
        }
    }