Example #1
0
    void Shoot()
    {
        if (Time.time > nextShotTime)
        {
            // Burst fire logic
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            // Single fire logic
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            foreach (Transform proj in projectileSpawn)
            {
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectile newProjectile = Instantiate(projectile, proj.position, proj.rotation) as Projectile;
                newProjectile.SetSpeed(muzzleVelocity);
            }

            // Shell spawning
            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();
        }
    }
Example #2
0
    void Shoot()
    {
        if (Time.time > nextShotTime)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawn.Length; i++)
            {
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectile newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectile;
                newProjectile.SetSpeed(muzzleVelocity);
            }
            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();
        }
    }
Example #3
0
    public void Shoot()
    {
        if (CanShoot())
        {
            Ray        ray = new Ray(spawn.position, spawn.forward);
            RaycastHit hit;

            float distanceShot = 20f;

            if (Physics.Raycast(ray, out hit, distanceShot))
            {
                distanceShot = hit.distance;
            }

            nextPossibleShootTime = Time.time + secondsBetweenShots;

            GetComponent <AudioSource>().PlayOneShot(clip);
            //if (tracer) StartCoroutine("RendreTracer",ray.direction * distanceShot);

            Projectile newProjectile = Instantiate(projectile, spawn.transform.position, spawn.rotation);
            newProjectile.SetSpeed(10f);

            Rigidbody newShell = Instantiate(shell, shellSpawn.position, Quaternion.identity) as Rigidbody;
            newShell.AddForce(shellSpawn.forward * Random.Range(150f, 200f) + spawn.forward * Random.Range(-10f, 10f));

            muzzleFlash.Activate();
        }
    }
Example #4
0
    void Shoot()
    {
        if (Time.time > nextShotTime)
        {
            if (fireMode == FireMode.Burst) //Ver se o Burst ainda tem tiros
            {
                if (shootRemainingInBurst == 0)
                {
                    return;
                }
                shootRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single) //Single Shoot
            {
                if (!triggerReleaseSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawn.Length; i++)
            {
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectile newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectile;
                newProjectile.SetSpeed(muzzleVelocity);
            }
            muzzleflash.Activate(); //Activar o efeito de tiro

            //Shoot Sound
            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }
Example #5
0
    private void Shoot()
    {
        if (Time.time > _nextFireTime)
        {
            if (currentBulletsCount > 0)
            {
                multipleShot = false;
                //StartCoroutine(cameraShake.Shake(.15f, .1f));
                _nextFireTime = Time.time + timeBetweenFire / 1000;

                TripleShoot();

                _muzzleFlash.Activate();
                Instantiate(shell, shellSpawn.position, shellSpawn.rotation);

                _animator.SetTrigger("shoot");
                currentBulletsCount--;
                gameManager.GetComponent <ShotgunBarController>().ChangeBulletsText(currentBulletsCount);
                GameObject.FindGameObjectWithTag("variables").GetComponent <Variables>().SetCurrentBulletCount(currentBulletsCount);
                shotSound.Play();
            }
            else
            {
                emptyShot.Play();
                _nextFireTime = Time.time + timeBetweenFire / 1000;
            }
        }
    }
Example #6
0
    // Shoot() function gets called by the Player and Enemy classes. It shoots a bullet in burst or automatic rifle modes
    public void Shoot()
    {
        /*
         *  The following algorithm decides whether a bullet can be shot, and shoots one if necessary
         */

        // Stores whether a bullet can be shot, its value (true or false) is decided from the conditions below
        bool shootable = false;

        if (gunType == GunType.Auto)
        {
            // If we are allowed to shoot i.e. a small delay between the last bullet has happened
            if (Time.time >= nextPossibleShootTime)
            {
                // Then we can shoot
                shootable = true;
                // Calculate the next time a bullet can be fired after
                nextPossibleShootTime = Time.time + (autoModeShotDelay / 1000);
            }
        }
        // For burst mode
        else if (gunType == GunType.Burst)
        {
            // Remove destroyed bullets (if the bullets are null)
            activeBurstBullets.RemoveAll((x) => { return(x == null); });
            // Condition for a bullet to be shot:
            // 1. Enough time has passed since the last bullet being fired
            // 2. The number of bullets that are in the game arena (activeBurstBullets.Count) is less than the
            // maximum number of bullets that a burst can fire (burstSize)
            if ((Time.time >= nextPossibleShootTime) && (activeBurstBullets.Count < burstSize))
            {
                // Then we can shoot
                shootable = true;
                // Calculate next shoot time
                nextPossibleShootTime = Time.time + delayBetweenBursts;
            }
        }

        // If after all the conditional checking we may shoot a bullet...
        if (shootable)
        {
            // Instantiate a bullet
            Bullet b = Instantiate(bullet, bulletExitPt.position, transform.rotation) as Bullet;
            b.speed           = bulletSpeed;                                // Set it's speed
            b.gunDamageAmount = gunDamage;                                  // Set how much damage it will deliver
            activeBurstBullets.Add(b);                                      // Add it to the List<> of active bullets in the world
            Instantiate(shell, shellExitPt.position, shellExitPt.rotation); // Instantiate a Shell with RNG force valuess
            try {
                audioSource.PlayOneShot(audioSource.clip);
            } catch { }; // Play the Bullet SFX audio
            // Flash muzzle sprites
            muzzleFlash.Activate();
            // Apply recoil i.e. move the gun's position slightly backwards to simualate recoil (initialPosition) but return back to the original
            transform.localPosition -= transform.forward * recoilStrength;
            // Shake camera when bullet fired
            Camera.main.GetComponent <CameraShake>().Shake();
        }
    }
Example #7
0
    public override void Shoot()
    {
        base.Shoot();
        if (!isReloading && Time.time > nextShotTime && projectilesRemainingInMag > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawns.Length; i++)
            {
                if (projectilesRemainingInMag == 0)
                {
                    break;
                }

                nextShotTime = Time.time + msBetweenShots / 1000f;

                float      randomX  = weaponController.player.isZoomedIn ? Random.Range(-spreadAmount, spreadAmount) / 2 : Random.Range(-spreadAmount, spreadAmount);
                float      randomY  = weaponController.player.isZoomedIn ? Random.Range(-spreadAmount, spreadAmount) / 2 : Random.Range(-spreadAmount, spreadAmount);
                float      randomZ  = weaponController.player.isZoomedIn ? Random.Range(-spreadAmount, spreadAmount) / 2 : Random.Range(-spreadAmount, spreadAmount);
                Quaternion spawnRot = projectileSpawns[i].rotation * Quaternion.Euler(randomX, randomY, randomZ);

                Projectile newProjectile = Instantiate(projectile, projectileSpawns[i].position, spawnRot) as Projectile;
                newProjectile.SetSpeed(muzzleVelocity);
                float bulletDamage = Random.Range(minDamagePerShot, maxDamagePerShot);
                float critValue    = Random.Range(0, 100);
                bool  isCrit       = false;
                if (critValue < critChance)
                {
                    isCrit        = true;
                    bulletDamage *= critModifier;
                }
                bulletDamage = Mathf.Round(bulletDamage);
                newProjectile.SetDamage(bulletDamage, isCrit);
            }
            projectilesRemainingInMag--;
            MakeNoise();
            anim.SetTrigger("Attack");
            muzzleflash.Activate();
            TriggerOnUpdateInfo();
            audioSource.PlayOneShot(audioShoot);
            recoilAngle += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
            recoilAngle  = Mathf.Clamp(recoilAngle, 0, 30);
        }
    }
Example #8
0
 public virtual void Shoot()
 {
     if (Time.time > nextShotTime && (bulletsRemaining > 0 || bulletsRemaining == -1) && !reloading)
     {
         nextShotTime = Time.time + msBetweenShots / 1000;
         Quaternion randRot = Quaternion.Euler(0, Random.Range(-spread / 2, spread / 2), 0);
         Ray        ray     = new Ray(transform.position, transform.forward);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, distToMuzzle, collisionMask, QueryTriggerInteraction.Collide))
         {
             Projectile newProjectile = Instantiate(projectile, transform.position, transform.rotation * randRot) as Projectile;
             newProjectile.SetSpeed(bulletSpeed);
             newProjectile.SetDamage(damage);
             newProjectile.SetKnockForce(knockBackForce);
             if (OnShoot != null)
             {
                 OnShoot(newProjectile);
             }
         }
         else
         {
             for (int i = 0; i < muzzle.Length; i++)
             {
                 Projectile newProjectile = Instantiate(projectile, muzzle[i].position, muzzle[i].rotation * randRot) as Projectile;
                 newProjectile.SetSpeed(bulletSpeed);
                 newProjectile.SetDamage(damage);
                 newProjectile.SetKnockForce(knockBackForce);
                 if (OnShoot != null)
                 {
                     OnShoot(newProjectile);
                 }
             }
         }
         for (int i = 0; i < shellEjectors.Length; i++)
         {
             if (shellEjectors[i].gameObject.active)
             {
                 Instantiate(shell, shellEjectors[i].position, shellEjectors[i].rotation);
             }
         }
         muzzleFlash.Activate();
         transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y);
         recoilAngle             += Random.Range(angleMinMax.x, angleMinMax.y);
         recoilAngle              = Mathf.Clamp(recoilAngle, 0, angleMinMax.y);
         if (!unlimitedMag)
         {
             bulletsRemaining--;
         }
         if (bulletsRemaining <= 0)
         {
             StartCoroutine(Reload());
         }
         if (AudioManager.instance != null)
         {
             AudioManager.instance.PlaySound(shotSound);
         }
     }
 }
Example #9
0
 void Shoot()
 {
     if (Input.GetButton("Fire1") && Time.time > timeOfNextShot)
     {
         audioSource.Play();
         GameObject projectile = Instantiate(Bullet, ProjectileOrigin.transform.position, ProjectileOrigin.transform.rotation);
         timeOfNextShot = Time.time + FireRate / 1000;
         muzzleFlash.Activate();
     }
 }
Example #10
0
    void spawnBullet()
    {
        // Instantiate(hiddenBullet, hiddenBulletEmitter.position, hiddenBulletEmitter.rotation);

        if (powerup)
        {
            if (!powerActivatedCheck)
            {
                Instantiate(roundEff, transform.position, Quaternion.identity);
                powerActivatedCheck = true;
                //lineParticle.SetActive(true);
                GameObject go = Instantiate(bigCircle, transform.position, Quaternion.identity);
                Destroy(go, 2f);
                Instantiate(BulletB, bulletEmitter.position, bulletEmitter.rotation);
                muzzleflash.Activate();

                //GameObject go2= Instantiate(BulletExplosion, bulletEmitter.position, bulletEmitter.rotation);
                //Destroy(go2,2f);
            }


            soundManager sm = GameObject.FindObjectOfType(typeof(soundManager)) as soundManager;
            sm.laserFn();
        }
        else
        {
            Instantiate(bullet, bulletEmitter.position, Quaternion.identity);
            muzzleflash.Activate();
            soundManager sm = GameObject.FindObjectOfType(typeof(soundManager)) as soundManager;
            sm.fireFn();

            /*  for (int i = 0; i < bulletEmitter.Length; i++)
             * {
             *    Instantiate(bullet, bulletEmitter[i].position, bulletEmitter[i].rotation);
             *    muzzleflash.Activate();
             *    soundManager sm = GameObject.FindObjectOfType(typeof(soundManager)) as soundManager;
             *    sm.fireFn();
             *    //CameraShaker.Instance.ShakeOnce(.5f, 1f, 0.1f, 0.01f);
             * }*/
        }
        //Time.timeScale = 0f;
    }
Example #11
0
    private IEnumerator ShotEffect()
    {
        //Turn on our line renderer
        laserLine.enabled = true;

        muzzleFlash.Activate();
        //Wait for .07 seconds
        yield return(shotDuration);

        //Deactivate our line renderer after waiting
        laserLine.enabled = false;
    }
Example #12
0
    public void Shoot()
    {
        if (Time.time > nextShotTime)
        {
            nextShotTime = Time.time + msBetweenShots / 1000;
            Projectile newProjectile = Instantiate(projectile, muzzle.position, muzzle.rotation) as Projectile;
            newProjectile.SetSpeed(muzzleVelocity);

            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleflash.Activate();
        }
    }
Example #13
0
    public void Shoot()
    {
        if (Time.time > nextShotTime)
        {
            nextShotTime = Time.time + millisecondsBetweenShots / 1000;
            Projectiles newProjectiles = Instantiate(projectiles, muzzle.position, muzzle.rotation) as Projectiles;
            newProjectiles.newProjectileSpeed(muzzleVelocity);

            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();
        }
    }
Example #14
0
    public void Launch()
    {
        if (Time.timeScale > 0)
        {
            //Instantiate a copy of our projectile and store it in a new rigidbody variable called clonedBullet
            Rigidbody clonedBullet = Instantiate(projectile, bulletSpawn.position, transform.rotation) as Rigidbody;

            //Add force to the instantiated bullet, pushing it forward away from the bulletSpawn location, using projectile force for how hard to push it away
            clonedBullet.AddForce(bulletSpawn.transform.forward * projectileForce);

            muzzleFlash.Activate();
        }
    }
    void Shoot()
    {
        if (Time.time > nextShotTime && ammoRemaining > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawn.Length; i++)
            {
                if (ammoRemaining == 0)
                {
                    break;
                }
                ammoRemaining--;
                if (ammoRemaining == 0)
                {
                    DamagePopup popupInstance = Instantiate(ammoPopup, transform.position + Vector3.up * 2f, Quaternion.AngleAxis(70, Vector3.right)) as DamagePopup;
                    popupInstance.JustStart(2f, transform.position + Vector3.up * 2f);
                }
                nextShotTime = Time.time + RateOfFire / 1000;
                Projectiles newBullet = Instantiate(bullet, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectiles;
                newBullet.SetSpeed(muzzleVel);
                newBullet.SetDamage(bulletDamage + (int)Random.Range(-damageVariance, damageVariance));
            }
            if (UpdateAmmo != null)
            {
                UpdateAmmo();
            }
            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();

            transform.localPosition -= Vector3.forward * .2f;
            recoilAngle             += recoilPerShot;
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, maxRecoilAngle);

            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }
Example #16
0
 void Shoot()
 {
     if (!isReloading && Time.time > nextShotTime && projectilesRemainingInMag > 0)
     {
         if (fireMode == FireMode.Burst)
         {
             if (shotsRemainingInBurst == 0)
             {
                 return;
             }
             shotsRemainingInBurst--;
         }
         else if (fireMode == FireMode.Single)
         {
             if (!triggerReleasedSinceLastShot)
             {
                 return;
             }
         }
         for (int i = 0; i < projectileSpawn.Length; i++)
         {
             if (projectilesRemainingInMag == 0)
             {
                 break;
             }
             projectilesRemainingInMag--;
             nextShotTime = Time.time + msBetweenShots / 1000;
             Projectile newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectile;
             newProjectile.SetSpeed(muzzleVelocity);
         }
         Instantiate(shell, shellEjection.position, shellEjection.rotation);
         muzzleflash.Activate();
         transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y);
         recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
         recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);
         AudioManager.instance.PlaySound(shootAudio, transform.position);
     }
 }
Example #17
0
    void Shoot()
    {
        if (!isReloading && Time.time > nextShotTime && this.projectilesRemainingInMagazine > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotRemainingInBurst == 0)
                {
                    return;
                }
                shotRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawnLocations.Length; i++)
            {
                if (projectilesRemainingInMagazine == 0)
                {
                    break;
                }
                projectilesRemainingInMagazine--;
                UpdateShotTimer();
                Projectile newProjectile = Instantiate(
                    projectile,
                    projectileSpawnLocations[i].position,
                    projectileSpawnLocations[i].rotation
                    ) as Projectile;
                newProjectile.Speed = muzzleVelocity;
            }

            // expel the shell casings
            Instantiate(shellCasing, shellEjectionPoint.position, shellEjectionPoint.rotation);

            // display the muzzle flash
            muzzleFlash.Activate();

            // recoil on the weapon (use random value for kickback range)
            transform.localPosition -= Vector3.forward * Random.Range(recoilKickbackMinMax.x, recoilKickbackMinMax.y);
            recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);
        }
    }
Example #18
0
    public void Shoot()
    {
        if (Time.time > nextShotTime && !isReloading && hasAmmo)
        {
            nextShotTime = Time.time + msBetweenShots / 1000;
            Projectile newProjectile = Instantiate(projectile, muzzle.position, muzzle.rotation) as Projectile; // spawn bullet
            newProjectile.SetSpeed(muzzleVelocity);                                                             // set speed of the bullet

            Instantiate(shell, shellEjection.position, shellEjection.rotation);                                 // create shell to eject
            muzzleflash.Activate();                                                                             // muzzle flash flash
            GameObject.FindGameObjectWithTag("MainPlayer").transform.localPosition -= Vector3.forward * .1f;    // kickback player
            AudioManager.instance.PlaySound(shootAudio, transform.position);
            //cameraShake.Shake(0.15f, 0.4f));

            animator.SetInteger("WeaponType_int", 6);

            //GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraShake>().ShakeCamera(10f, 10f);
            //myCam.GetComponent<CameraShake>().ShakeCamera(0.1f, 0.01f);
            myCam.GetComponent <CameraShake>().myShake();

            // reloading
            if (bulletsInMagCurrent > 0)
            {
                bulletsInMagCurrent--;
            }
            else
            {
                StartCoroutine(Reload()); // wait for 2 seconds
                if (magazines > 0)
                {
                    magazines--;
                    Reloading();
                    bulletsInMagCurrent = bulletsInMagMaximum;
                }
                else
                {
                    print("has no ammo");
                    AudioManager.instance.PlaySound(dryFIre, transform.position);
                    hasAmmo = false; // doint forget to change it after AMMO pickup
                }
            }
        }
        else if (Time.time > nextShotTime && !isReloading && !hasAmmo)
        {
            AudioManager.instance.PlaySound(dryFIre, transform.position);
            nextShotTime = Time.time + msBetweenShots / 1000;
        }
    }
Example #19
0
    public void Shoot()
    {
        if (Time.time > nextShootTime)
        {
            muzzleFlash.Activate();

            nextShootTime = Time.time + msBetweenShots / 1000;
            Projectile newProjectile = Instantiate(bullet, muzzle.position, muzzle.rotation);
            newProjectile.speed  = bulletSpeed;
            newProjectile.damage = bulletDamage;
            newProjectile.deltaY = Random.Range(-bulletDeltaY, bulletDeltaY);
            newProjectile.deltaZ = Random.Range(-bulletDeltaZ, bulletDeltaZ);

            Instantiate(shell, shellBornPoint.position, shellBornPoint.rotation);
        }
    }
Example #20
0
    void Shoot()
    {
        AlignTarget();

        if (!isReloading && Time.time > nextShootTime && projectilesRemainingInMag > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shootsRemainingInBurst == 0)
                {
                    return;
                }
                shootsRemainingInBurst--;
            }

            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            //Bullet
            for (int i = 0; i < muzzles.Length; i++)
            {
                if (projectilesRemainingInMag == 0)
                {
                    break;
                }
                projectilesRemainingInMag--;
                nextShootTime = Time.time + msBetweenShots / 1000;
                Bullet bullet = Instantiate(projectile, muzzles[i].position, muzzles[i].rotation) as Bullet;
                bullet.SetSpeed(muzzleVelocity);
            }

            //Shell
            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();
            transform.localPosition -= Vector3.forward * Random.Range(recoilMoveMinMax.x, recoilMoveMinMax.y);

            if (AudioManager.instance != null)
            {
                AudioManager.instance.PlaySound(shootAudio, transform.position);
            }
        }
    }
Example #21
0
    private void Shoot()
    {
        if (!m_IsReloading && Time.time > m_NextShotTime && m_AmmunitionsRemainingInMagazine > 0)
        {
            if (m_FireMode == FireMode.Burst)
            {
                if (m_ShotsRemainingInBurst == 0)
                {
                    return;
                }

                m_ShotsRemainingInBurst--;
            }
            else if (m_FireMode == FireMode.Single)
            {
                if (!m_TriggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < m_Muzzle.Length; i++)
            {
                if (m_AmmunitionsRemainingInMagazine == 0)
                {
                    break;
                }

                m_AmmunitionsRemainingInMagazine--;

                // The time between shots is calculated in miliseconds, then the bullet is instantiated and it is given a set speed depeding on the gun.
                m_NextShotTime = Time.time + m_MSBetweenShots / 1000f;

                Projectile newProjectile = Instantiate(m_Projectile, m_Muzzle[i].position, m_Muzzle[i].rotation) as Projectile;
                newProjectile.SetSpeed(m_MuzzleVelocity);
            }

            Instantiate(m_Shell, m_ShellExtraction.position, m_ShellExtraction.rotation);
            m_MuzzleFlash.Activate();
            transform.localPosition -= Vector3.forward * Random.Range(m_KickMinMax.x, m_KickMinMax.y);
            m_RecoilAngle           += Random.Range(m_RecoilAngleMinMax.x, m_RecoilAngleMinMax.y);
            m_RecoilAngle            = Mathf.Clamp(m_RecoilAngle, 0f, 30f);

            AudioManager.m_Instance.PlaySound(m_ShootAudio, transform.position);
        }
    }
Example #22
0
    void Shoot()
    {
        if (!isReloading && Time.time > nextShotTime && remainingProjectiles > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingBurst == 0)
                {
                    return;
                }

                shotsRemainingBurst--;
            }

            if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < muzzle.Length; i++)
            {
                if (remainingProjectiles == 0)
                {
                    break;
                }
                remainingProjectiles--;
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectile newProjectile = Instantiate(projectile, muzzle[i].position, muzzle[i].rotation) as Projectile;
                newProjectile.setSpeed(muzzleVelocity);
            }

            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();

            //on each shoot, the gun kick back itself
            transform.localPosition += Vector3.forward * Random.Range(recoilKickMinMax.x, recoilKickMinMax.y);
            recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);

            AudioManager.instance.PlaySound(shootSound, transform.position);
        }
    }
Example #23
0
    public override void Use()
    {
        if (currentAmmoAmount > 0 && Time.time > nextShotTime)
        {
            currentAmmoAmount--;
            nextShotTime = Time.time + msBetweenShots / 1000;
            Projectile newProjectile = PoolManager.instance.ReuseObject(projectile.gameObject, muzzle.position, muzzle.rotation).GetComponent <Projectile>();

            newProjectile.SetSpeed(muzzleVelocity);
            newProjectile.SetDamage(damage);
            newProjectile.SetShootingWeapon(this);

            //PoolManager.instance.ReuseObject(shell.gameObject, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();

            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }
Example #24
0
    private void Shoot()
    {
        if (!isReloading && Time.time > _nextShotTime && projectilesRemainingInMag > 0)
        {
            if (FireModeType == FireMode.Burst)
            {
                if (_shotRemainingInBurst == 0)
                {
                    return;
                }

                _shotRemainingInBurst--;
            }
            else if (FireModeType == FireMode.Single)
            {
                if (!_triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            foreach (Transform t in ProjectileSpawn)
            {
                if (projectilesRemainingInMag == 0)
                {
                    break;
                }

                projectilesRemainingInMag--;
                _nextShotTime = Time.time + MsBetweenShots / 1000;
                Projectile newProjectile = Instantiate(Projectile, t.position, t.rotation);
                newProjectile.SetSpeed(MuzzleVelocity);
            }

            Instantiate(Shell, ShellInjection.position, ShellInjection.rotation);
            _muzzleFlash.Activate();

            transform.localPosition -= Vector3.forward * Random.Range(KickbackMinMax.x, KickbackMinMax.y);
            _recoilAngle            += Random.Range(RecoilAngleMinMax.x, RecoilAngleMinMax.y);
            _recoilAngle             = Mathf.Clamp(_recoilAngle, 0, 60);

            AudioManager.instance.PlaySound(ShootAudio, transform.position);
        }
    }
Example #25
0
    void Shoot()
    {
        //Check if shooting allowed
        if (!isReloading && Time.time > nextShotTime && projectilesRemainingInMag > 0)
        {
            //Deal with different fire modes
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }
            //Shoot projectiles
            foreach (Transform projectileSpawn in projectileSpawns)
            {
                if (projectilesRemainingInMag == 0)
                {
                    break;
                }
                projectilesRemainingInMag--;
                Projectile newProjectile = Instantiate(projectile, projectileSpawn.position, projectileSpawn.rotation) as Projectile;
                newProjectile.setSpeed(muzzleVelocity);
                nextShotTime = Time.time + msBetweenShots / 1000;
            }
            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();

            AudioManager.instance.PlaySound(shootAudio, transform.position);

            //Recoil
            transform.localPosition -= Vector3.forward * Random.Range(kickkMinMax.x, kickkMinMax.y);
            recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, maxRecoilAngle);
        }
    }
    //shoot bullet
    void Shoot()
    {
        if (!isReloading && Time.time > nextShotTime && projectileRemainingInMag > 0) //if is not reloading, cooldown of next shot is ready, and have bullet to shoot
        {
            if (fireMode == FireMode.Burst)                                           //if is burst fire mode
            {
                if (shotsRemainingInBurst == 0)                                       //if there is not enough bullet avaliable to sohot
                {
                    return;                                                           //jump out
                }
                shotsRemainingInBurst--;                                              //decrease bullet remaining to burst
            }
            else if (fireMode == FireMode.Single)                                     //if is single fire mode
            {
                if (!triggerReleaseSinceLastShot)                                     //if is holding the trigger after bullet shoot
                {
                    return;                                                           //jump out
                }
            }

            //Mag
            for (int i = 0; i < projectileSpawn.Length; i++)                                                                                //for each projectile spawner
            {
                if (projectileRemainingInMag == 0)                                                                                          //if there is no bullet to shoot
                {
                    break;                                                                                                                  //jump out from loop
                }
                projectileRemainingInMag--;                                                                                                 //decrese bullet remaining in to shoot
                nextShotTime = Time.time + msBetweenShots / 1000;                                                                           //set cooldown for next shot
                Projectile newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectile; //create bullet
                newProjectile.SetSpeed(muzzleVelocity);                                                                                     //set speed of bullet using projectile's "SetSpeed" function
            }
            //shell animation
            Instantiate(shell, shellEjection.position, shellEjection.rotation);                    //create shell
            muzzleflash.Activate();                                                                //run MuzzleFlash's "Activate" function
            transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y); //launch the shell
            recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);     //random set recoil angle
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);                            //clamp the recoil angle from 0 to 30

            AudioManager.instance.PlaySound(shootAudio, transform.position);                       // play shooting sound slip using audio manager script
        }
    }
Example #27
0
    void Shoot()     // shoot behöver inte vara public, för vi kallar på den i OnTriggerHold()
    {
        if (!isReloading && Time.time > nextShotTime && projectilesRemainingInMagazine > 0)
        {
            if (fireMode == Firemode.Burst)
            {
                if (shotsRemainingInBurst == 0)                //om det är s**t på burst skotten, avsluta metoden.
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == Firemode.Single)
            {
                if (!triggerReleasedSinceLastTrigger)
                {
                    return;
                }
            }

            //Nedan är loopen om vi skjuter flera skott på samma gång. Med tex ett shotgun.
            for (int i = 0; i < projectileSpawn.Length; i++)
            {
                if (projectilesRemainingInMagazine == 0)
                {
                    break;
                }
                projectilesRemainingInMagazine--;
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectile newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectile;
                newProjectile.SetSpeed(muzzleVelocity);
            }

            Instantiate(shell, shellEject.position, shellEject.rotation);
            _muzzleFlash.Activate();

            //Rekylen på vapnet per skott
            transform.localPosition -= Vector3.forward * Random.Range(kickBackMinMax.x, kickBackMinMax.y);
            recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);
        }
    }
Example #28
0
    public void Shoot()
    {
        if (Time.time > nextShotTime && !isReloading && projectilesRemaining > 0)
        {
            projectilesRemaining--;

            nextShotTime = Time.time + msBetweenShots / 1000;
            Projectile newProjectile = PoolManager.instance.ReuseObject(projectile.gameObject, muzzle.position, muzzle.rotation).GetComponent <Projectile>();
            //Projectile newProjectile = (Projectile) Instantiate(projectile, muzzle.position, muzzle.rotation);
            newProjectile.SetSpeed(muzzleVelocity);

            PoolManager.instance.ReuseObject(shell.gameObject, shellEjection.position, shellEjection.rotation);
            //Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();

            transform.localPosition -= Vector3.forward * recoil;

            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }
Example #29
0
    void Shoot()
    {
        #region checks : time & firemode
        if (Time.time <= nextShotTime || remainingInMag == 0 || isReloading)
        {
            return;
        }

        if (fireMode == FireMode.Burst)
        {
            if (shotRemainingInBurst == 0)
            {
                return;
            }
            shotRemainingInBurst--;
        }
        if (fireMode == FireMode.Single && !triggerReleased)
        {
            return;
        }

        #endregion
        remainingInMag--;

        for (int i = 0; i < muzzle.Length; i++)
        {
            nextShotTime  = Time.time + msBetweenShots / 1000;
            newProjectile = Instantiate(projectile, muzzle[i].position, muzzle[i].rotation) as Projectile;
            newProjectile.SetSpeed(muzzleVelocity);
        }

        Instantiate(shell, shellEjector.position, shellEjector.rotation);
        muzzleFlash.Activate();

        transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y);
        recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
        recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);

        AudioManager.instance.PlaySound(shootAudio);
    }
Example #30
0
    void Shoot()
    {
        if (!isReloading && Time.time > nextShotTime && shotsRemainingMag > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingBurst == 0)
                {
                    return;
                }
                shotsRemainingBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleased)
                {
                    return;
                }
            }

            for (int i = 0; i < muzzle.Length; i++)
            {
                if (shotsRemainingMag == 0)
                {
                    break;
                }
                shotsRemainingMag--;
                nextShotTime = Time.time + fireRate / 1000;
                Projectile newBullet = Instantiate(bullet, muzzle[i].position, muzzle[i].rotation) as Projectile;
                newBullet.SetGunOptions(bulletSpeed, damage, bulletLifeSpan, bulletRicochet);
            }
            Instantiate(shell, shellEject.position, shellEject.rotation);
            muzzleFlash.Activate();
            transform.localPosition -= Vector3.forward * Random.Range(kickBackLimits.x, kickBackLimits.y);
            recoilAngle             += Random.Range(recoilAngleLimits.x, recoilAngleLimits.y);
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);

            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }