Exemplo n.º 1
0
    void TryShoot()
    {
        //检测是否需要换弹
        if (curAmmo <= 0)
        {
            if (leftAmmo > 0)
            {
                StartCoroutine(Reload());
            }
            else
            {
                Debug.Log("弹药全部用完了!");
            }
            return;
        }

        float shootInterval = Time.time - lastShootTime;

        lastShootTime = Time.time;
        curAmmo--;

        //播放射击动画


        //播放枪口特效
        weaponGraphics.PlayMuzzleFlash();

        //发射子弹
        bulletManager.FireBullet();

        //施加后座力
        float coefficient      = Mathf.Lerp(1, 0, (shootInterval - delayBetweenShots) / (5 * delayBetweenShots));
        float horizontalRecoil = UnityEngine.Random.Range(-horizontalRecoilForce, horizontalRecoilForce);

        StartCoroutine(mouseLook.ApplyScreenShake(horizontalRecoil * coefficient, verticalRecoilForce * coefficient));

        //播放射击音效
    }