private void Update()
    {
        if (isClient)
        {
            return;
        }

        int f1 = (int)Input.GetAxisRaw("Fire1");


        switch (f1)
        {
        case 0:
            canFire = true;
            break;

        case 1:
            if (canFire)
            {
                fire.Fire();
                canFire = false;
            }
            break;

        default:
            break;
        }
    }
Exemple #2
0
    private void FixedUpdate()
    {
        if (!control)
        {
            return;
        }
        bool emptySouldPlay = false;

        if (Input.GetKey(KeyCode.W) && !backGunOverHeat)
        {
            if (CanFire(lastFireBack, backFireFreq))
            {
                rb.AddForceAtPosition(transform.up * (backForce + currentBackForceIncrease), LBack.position, ForceMode2D.Impulse);
                rb.AddForceAtPosition(transform.up * (backForce + currentBackForceIncrease), RBack.position, ForceMode2D.Impulse);
                lastFireBack = Time.time;

                bulletFire.FireMinigun(LBack.position, -transform.up, backSpeed, 0, backGunDamage);
                bulletFire.FireMinigun(RBack.position, -transform.up, backSpeed, 1, backGunDamage);
            }

            foreach (ParticleSystem ps in mainGunEffects)
            {
                if (!ps.isPlaying)
                {
                    ps.Play();
                }
            }

            backShake.GenerateImpulse(-transform.up);

            currentBackForceIncrease += backgunForceIncreaseOvertime * Time.fixedDeltaTime;
            if (currentBackForceIncrease > backgunForceIncreaseOvertimeMax)
            {
                currentBackForceIncrease = backgunForceIncreaseOvertimeMax;
            }

            if (backGunSE.audioSource.volume < 0.5 && backGunSE.fadeSpeed <= 0)
            {
                backGunSE.FadeTo(backGunFadeInTime, 0.5f);
            }

            backGunHeat += backGunHeatIncrease * Time.fixedDeltaTime;
            backGunSE.audioSource.pitch = Mathf.Lerp(backGunSoundPitchMinHeat, backGunSoundPitchMaxHeat, backGunHeat / backGunMaxHeat);
            if (backGunHeat > backGunMaxHeat)
            {
                backGunHeat     = backGunMaxHeat;
                backGunOverHeat = true;
                backGunOverheatSE.Play();
                backGunOverheatAlarmSE.Play();
            }
        }
        else
        {
            if (backGunSE.audioSource.volume > 0 && backGunSE.fadeSpeed >= 0)
            {
                backGunSE.FadeTo(backGunFadeOutTime, 0);
            }

            foreach (ParticleSystem ps in mainGunEffects)
            {
                ps.Stop();
            }


            currentBackForceIncrease -= backgunForceDecreaseOvertime * Time.fixedDeltaTime;
            if (currentBackForceIncrease < 0)
            {
                currentBackForceIncrease = 0;
            }

            if (backGunOverHeat)
            {
                backGunHeat -= backGunOverHeatDecrease * Time.fixedDeltaTime;
                if (backGunHeat <= 0)
                {
                    backGunOverHeat = false;
                    backGunHeat     = 0;
                }
            }
            else
            {
                backGunHeat -= backGunHeatDecrease * Time.fixedDeltaTime;
                if (backGunHeat <= 0)
                {
                    backGunHeat = 0;
                }
            }
        }
        if (Input.GetKey(KeyCode.A))
        {
            if (CanFire(lastFireLeft, leftFireFreq) && Time.time - lastLeftGunReload > sideGunReloadTime && leftGunMag > 0)
            {
                rb.AddForceAtPosition(transform.right * midForce * Time.fixedDeltaTime, LMid.position, ForceMode2D.Impulse);
                lastFireLeft = Time.time;

                bulletFire.Fire(LMid.position, -transform.right, sideSpeed, BulletType.handgun, sideGunDamage);
                sideShake.GenerateImpulse();
                sideGunSE.pitch = Mathf.Lerp(sideGunSoundPitchMax, sideGunSoundPitchMin, (float)leftGunMag / sideGunSlot);
                sideGunSE.Play();

                leftGunMag -= 1;
                if (leftGunMag == 0)
                {
                    lastLeftGunReload = Time.time;
                    leftGunMag        = sideGunSlot;
                }
            }
            else if (Time.time - lastLeftGunReload < sideGunReloadTime)
            {
                emptySouldPlay = true;
            }
        }
        if (Input.GetKey(KeyCode.D))
        {
            if (CanFire(lastFireRight, rightFireFreq) && Time.time - lastRightGunReload > sideGunReloadTime && rightGunMag > 0)
            {
                rb.AddForceAtPosition(-transform.right * midForce * Time.fixedDeltaTime, RMid.position, ForceMode2D.Impulse);
                lastFireRight = Time.time;

                bulletFire.Fire(RMid.position, transform.right, sideSpeed, BulletType.handgun, sideGunDamage);
                sideShake.GenerateImpulse();
                sideGunSE.pitch = Mathf.Lerp(sideGunSoundPitchMax, sideGunSoundPitchMin, (float)rightGunMag / sideGunSlot);
                sideGunSE.Play();

                rightGunMag -= 1;
                if (rightGunMag == 0)
                {
                    lastRightGunReload = Time.time;
                    rightGunMag        = sideGunSlot;
                }
            }
            else if (Time.time - lastRightGunReload < sideGunReloadTime)
            {
                emptySouldPlay = true;
            }
        }
        if (Input.GetKey(KeyCode.S))
        {
            if (CanFire(lastFireFront, frontFireFreq) && Time.time - lastFrontGunReload > frontGunReloadTime && frontGunMag > 0)
            {
                rb.AddForceAtPosition(-transform.up * frontForce, LFront.position, ForceMode2D.Impulse);
                rb.AddForceAtPosition(-transform.up * frontForce, RFront.position, ForceMode2D.Impulse);
                lastFireFront = Time.time;

                bulletFire.Fire(LFront.position, transform.up, frontSpeed, BulletType.shotgun, frontGunDamage);
                bulletFire.Fire(RFront.position, transform.up, frontSpeed, BulletType.shotgun, frontGunDamage);

                frontShake.GenerateImpulse(transform.up);
                frontGunSE.pitch = Mathf.Lerp(frontGunSoundPitchMax, frontGunSoundPitchMin, (float)frontGunMag / frontGunSlot);
                frontGunSE.Play();

                frontGunMag -= 1;
                if (frontGunMag == 0)
                {
                    lastFrontGunReload = Time.time;
                    frontGunMag        = frontGunSlot;
                }
            }
            else if (Time.time - lastFrontGunReload < frontGunReloadTime)
            {
                emptySouldPlay = true;
            }
        }


        if (Input.GetMouseButton(0))
        {
            if (CanFire(lastFireMain, mainFireFreq) && Time.time - lastMainGunReload > mainGunReloadTime && mainGunMag > 0)
            {
                rb.AddForceAtPosition(-mainGun.transform.up * mainForce, MainFire.position, ForceMode2D.Impulse);
                lastFireMain = Time.time;

                bulletFire.Fire(MainFire.position, mainGun.transform.up, mainSpeed, BulletType.maingun, mainGunDamage);
                mainShake.GenerateImpulse();
                mainGunSE.pitch = Mathf.Lerp(mainGunSoundPitchMax, mainGunSoundPitchMin, (float)mainGunMag / mainGunSlot);
                mainGunSE.Play();

                mainGunMag -= 1;
                if (mainGunMag == 0)
                {
                    lastMainGunReload = Time.time;
                    mainGunMag        = mainGunSlot;
                }
            }
            else if (Time.time - lastMainGunReload < mainGunReloadTime)
            {
                emptySouldPlay = true;
            }
        }

        if (emptySouldPlay && !emptySE.isPlaying)
        {
            emptySE.Play();
        }
        else if (!emptySouldPlay && emptySE.isPlaying)
        {
            emptySE.Stop();
        }

        BoundaryVelocityLimit();
    }
 public void setFire()
 {
     bulletFire.Fire();
 }