Beispiel #1
0
    public void OnTriggerDown(Vector3 firingDirection)
    {
        if (Time.unscaledTime < cd_ || awaitingRelease_)
        {
            return;
        }

        if (!ammoProvider_.TryUseAmmo(AmmoType, 1))
        {
            return;
        }

        cd_ = Time.unscaledTime + Cooldown;
        awaitingRelease_ = true;

        LatestFiringDirection    = firingDirection;
        LatestFiringTimeUnscaled = Time.unscaledTime;

        var position = transform_.position + firingDirection * 0.5f;

        Fire(position, firingDirection);
        forceReceiver_.SetMinimumForce(-firingDirection * 3);

        var particleCenter = transform_.position + firingDirection * 0.5f;

        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, particleCenter, 1);
        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, particleCenter, 10);
        audioManager_.PlaySfxClip(FireSound, 2, FireSoundPitchVariation, FireSoundPitch);
        cameraShake_.SetMinimumShake(1.0f);
    }
Beispiel #2
0
    IEnumerator <float> FireCo()
    {
        isFiring_ = true;

        while (true)
        {
            for (int i = 0; i < GunSettings.BurstCount; ++i)
            {
                var direction = latestFiringDirection_;
                var position  = transform_.position + direction * 0.5f;

                var angleOffsets = GetFiringAngleOffsets(GunSettings.FiringSpread, 1.0f);
                int bulletCount  = angleOffsets.Length;
                if (!ammoProvider_.TryUseAmmo(AmmoType, bulletCount))
                {
                    yield break;
                }

                for (int j = 0; j < bulletCount; ++j)
                {
                    float precisionPenalty = Mathf.Min(0.75f, Mathf.Max(0, -0.5f + penalty_ * 0.8f));
                    float precision        = GunSettings.Precision - precisionPenalty;

                    float       angleOffset = angleOffsets[j];
                    const float MaxDegreesOffsetAtLowestPrecision = 30.0f;
                    angleOffset += (Random.value - 0.5f) * (1.0f - precision) * MaxDegreesOffsetAtLowestPrecision;
                    var offsetDirection = Quaternion.AngleAxis(angleOffset, Vector3.forward) * direction;
                    Fire(position, offsetDirection);
                }

                latestFiringTime_ = Time.unscaledTime;

                audioManager_.PlaySfxClip(FireSound, 1, FireSoundPitchVariation, FireSoundPitch);
                cameraShake_.SetMinimumShake(0.75f);

                forceReceiver_.SetMinimumForce(-direction * Recoil);

                var particleCenter = position + direction * 0.3f;
                ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, particleCenter, 1);
                ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, particleCenter, 5);

                float timePenalty = Mathf.Min(0.2f, Mathf.Max(0, -0.5f + penalty_ * 0.4f));
                float waitEndTime = Time.realtimeSinceStartup + GunSettings.TimeBetweenShots + timePenalty;
                while (Time.realtimeSinceStartup < waitEndTime)
                {
                    yield return(0);
                }

                penalty_ = Mathf.Min(2.0f, penalty_ + 0.1f);
            }

            bool continueFiring = GunSettings.FiringMode == FiringMode.Auto && triggerIsDown_;
            if (!continueFiring)
            {
                break;
            }
        }

        isFiring_ = false;
    }
Beispiel #3
0
    public void OnTriggerDown(Vector3 firingDirection)
    {
        if (Time.unscaledTime < cd_ || awaitingRelease_)
        {
            return;
        }

        if (!ammoProvider_.TryUseAmmo(AmmoType, BulletCount))
        {
            return;
        }

        cd_ = Time.unscaledTime + Cooldown;
        awaitingRelease_ = true;

        LatestFiringDirection    = firingDirection;
        LatestFiringTimeUnscaled = Time.unscaledTime;

        float angle             = -AngleSpread * 0.5f;
        float angleStep         = AngleSpread / (BulletCount - 1);
        float angleMaxVariation = 10;

        for (int j = 0; j < BulletCount; ++j)
        {
            float positionRandomOffset = Random.value * 0.35f;
            var   position             = transform_.position + firingDirection * (0.375f + positionRandomOffset);

            float angleOffset = angle + Random.value * angleMaxVariation;
            angle += angleStep;
            var offsetDirection = Quaternion.AngleAxis(angleOffset, Vector3.forward) * firingDirection;
            Fire(position, offsetDirection);

            forceReceiver_.SetMinimumForce(-firingDirection * 3);
        }

        var particleCenter = transform_.position + firingDirection * 0.5f;

        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, particleCenter, 1);
        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, particleCenter, 5);
        audioManager_.PlaySfxClip(FireSound, 1, 0.1f);
        cameraShake_.SetMinimumShake(0.75f);
    }