Beispiel #1
0
    /*
     * Allows the player to switch to the next (or previous gun), shoot the gun, or reload the gun
     */
    void Update()
    {
        //statements to allow the player to switch guns forwards / backwards in the cycle
        if (Input.GetButtonDown("RBuffer") && Time.time > nextFire)
        {
            player.GetComponent <PlayerController> ().switchWeaponForwards();
        }

        if (Input.GetButtonDown("LBuffer") && Time.time > nextFire)
        {
            player.GetComponent <PlayerController> ().switchWeaponBackwards();
        }

        //allows the player to reload their gun if they're not in the fireRate cooldown period and have enough ammo
        if ((Input.GetAxis("XButton") > 0) && !reloading && bulletsInClip != clipSize && ammo > 0 && Time.time > nextFire)
        {
            reloading = true;
            reloadSound.Play();
            nextFire = Time.time + reloadTime;
            StartCoroutine(reload());
        }
        else if ((Input.GetAxis("XButton") > 0) && !reloading && bulletsInClip != clipSize && ammo == 0 && Time.time > nextFire)
        {
            emptyClipSound.Play();
            nextFire = Time.time + reloadTime;
        }

        //fires a bullet if the player is holding the trigger, aren't reloading and the time since last fire > fireRate
        if ((Input.GetAxis("ControllerFire1") > 0) && Time.time > nextFire && bulletsInClip > 0 && !reloading)
        {
            nextFire = Time.time + fireRate;             //sets time of nextFire based on the current time, and fireRate
            Instantiate(bullet, bulletSpawnTopMid.position, bulletSpawnTopMid.rotation);
            Instantiate(bullet, bulletSpawnTopLeft.position, bulletSpawnTopLeft.rotation);
            Instantiate(bullet, bulletSpawnTopRight.position, bulletSpawnTopRight.rotation);
            Instantiate(bullet, bulletSpawnMidMidLeft.position, bulletSpawnMidMidLeft.rotation);
            Instantiate(bullet, bulletSpawnMidMidRight.position, bulletSpawnMidMidRight.rotation);
            Instantiate(bullet, bulletSpawnMidLeft.position, bulletSpawnMidLeft.rotation);
            Instantiate(bullet, bulletSpawnMidRight.position, bulletSpawnMidRight.rotation);
            Instantiate(bullet, bulletSpawnBotMid.position, bulletSpawnTopMid.rotation);
            Instantiate(bullet, bulletSpawnBotLeft.position, bulletSpawnTopLeft.rotation);
            Instantiate(bullet, bulletSpawnBotRight.position, bulletSpawnTopRight.rotation);
            gunshotSound.Play();
            leftParticleSystem.Play();
            rightParticleSystem.Play();
            director.AddBullet();               //adds a bullet to the List in the director class (used for calculating BPM)
            director.AddBullet();
            director.AddBullet();
            director.AddBullet();
            director.ammoSpent += ammoSpentModifier;             //adds to the ammoSpent variable in the director, allowing it to spawn more ammo
            bulletsInClip--;
            ammo--;
            UpdateUI();
        }
        else if ((Input.GetAxis("ControllerFire1") > 0) && Time.time > nextFire && bulletsInClip == 0 && !reloading)
        {
            emptyClipSound.Play();
            nextFire = Time.time + fireRate;
        }
    }