Beispiel #1
0
    protected virtual void Shoot(float offset)
    {
        state = GunState.Recovering;

        int bulletsPerShot = mag.GetBulletsPerShot();

        for (int i = 0; i < bulletsPerShot; i++)
        {
            ProjectileContainer container = mag.GetNextBullet(i == bulletsPerShot - 1);
            float      angleOffset        = GetAccuracyModifier(stats.accuracy) * stats.spread * (Random.Range(0, 2) * 2 - 1);
            Quaternion rot = Quaternion.Euler(0, 0, barrelTip.rotation.eulerAngles.z + angleOffset);
            GameObject bullet;
            if (offset > 0)
            {
                float dist = container.stats.speed * offset;
                bullet = ObjectPooler.ForceSetObject(barrelTip.position + rot * Vector3.right * dist, rot);
            }
            else
            {
                bullet = ObjectPooler.ForceSetObject(barrelTip.position, rot);
            }

            activeBullets.Add(bullet);
            bullet.GetComponent <Projectile>().Initialize(container, this);
        }

        if (stats.burstCount > 1 && offset > stats.fireDelay) // Shoot multiple times per frame
        {
            Debug.LogWarning("Firing multiple per frame\n" + Mathf.Floor(offset / stats.fireDelay));
            GunUpdate(false);
        }
        else if (stats.burstCount <= 1 && offset > stats.burstDelay)
        {
            Debug.LogWarning("Bursting multiple per frame\n" + Mathf.Floor(offset / stats.burstDelay));
            GunUpdate(false);
        }
        else if (player != null) // Play Shoot FX (Sounds, anim, flash, rumble)
        {
            StartRumble(new Rumble(Rumble.bullet));
        }
    }