Exemple #1
0
    void Start()
    {
        //Update ammo.
        Ammo.AmmoUpdate();

        //If in challenge mode make gun to rise from bottom.
        if (ChallengeMenu.challengeMode)
        {
            transform.position = new Vector2(0, -4);
        }

        //First time gun will fly up automatically.
        StartCoroutine(ShootVerticallyUp(1f));
    }
Exemple #2
0
    void FixedUpdate()
    {
        //If player pressed space, gun still has ammo and it's not recoiling.
        if (Input.GetKey("space") && ammo > 0 && !recoil)
        {
            //Shoot.
            StartCoroutine(Shoot());
            //Update challenge stats.
            if (ChallengeMenu.challengeActive[1])
            {
                shotsFired++;
                Coroutines.AchieveChallenge(shotsFired, 30, 60, 100);
            }
        }
        //If player pressed space and gun has no ammo.
        else if (Input.GetKey("space") && ammo == 0)
        {
            //Play empty ammo sound.
            emptySound.Play();
            //Start red screen glow animation.
            ScreenGlow.StartGlow();

            //Start shaking camera.
            StartCoroutine(CameraShake.Shake(0.1f, 0.2f));
        }
        //If player touch screen with finger, gun still has ammo and it's not recoiling.
        if (FingerInput.isTouching && ammo > 0 && !recoil)
        {
            //Shoot.
            StartCoroutine(Shoot());
            //Update challenge stats.
            if (ChallengeMenu.challengeActive[1])
            {
                shotsFired++;
                Coroutines.AchieveChallenge(shotsFired, 30, 60, 100);
            }
        }
        //If player pressed touch screen but gun has no ammo.
        else if (FingerInput.isTouching && ammo == 0)
        {
            //Play empty ammo sound.
            emptySound.Play();
            //Start red screen glow animation.
            ScreenGlow.StartGlow();
#if UNITY_ANDROID
            //If vibrate is on vibrate device.
            if (SettingsMenu.vibration == 1)
            {
                Vibration.Vibrate(50);
            }
#endif
            //Start shaking camera.
            StartCoroutine(CameraShake.Shake(0.15f, 0.2f));
        }

        //If gun collide with booster.
        if (speedUp)
        {
            //Shoot gun up.
            StartCoroutine(ShootVerticallyUp(1f));
            //Start shaking camera.
            StartCoroutine(CameraShake.Shake(0.1f, 0.2f));
            //Disable speed bool.
            speedUp = false;
        }

        //If gun is reloading.
        if (reload)
        {
            //Reset ammo.
            ammo = fullAmmo;
            Ammo.AmmoUpdate();
            reload = false;
        }
    }
Exemple #3
0
    //If gun shoot.
    IEnumerator Shoot()
    {
        //Start recoil.
        recoil = true;

        //Reset spinning forces.
        ResetVelocity();

        //Enable gun shot animations.
        transform.GetChild(0).GetChild(0).GetComponent <Animation>().Play();
        transform.GetChild(1).GetChild(0).GetComponent <Animation>().Play();

        //Fly gun up according to it's own rotation.
        StartCoroutine(ShootVerticallyUp(Mathf.Abs(1 - (transform.GetChild(0).eulerAngles.z / 180))));
        ShootUp();

        //Change gun rotation.
        if (transform.GetChild(0).eulerAngles.z < 180)
        {
            ChangeTorque(rotationSpeed);
        }
        else
        {
            ChangeTorque(-rotationSpeed);
        }

#if UNITY_ANDROID
        //If vibrate is on vibrate device.
        if (SettingsMenu.vibration == 1)
        {
            Vibration.Vibrate(50);
        }
#endif

        //If gun shot is vertically down.
        if (transform.GetChild(0).eulerAngles.z >= -2.5f && transform.GetChild(0).eulerAngles.z <= 2.5f)
        {
            //If gun shot is not the first.
            if (!firstShot)
            {
                //Enable vertical shot animation and update achievements stats.
                VerticalShot.EnableAnimation();
                PlayerPrefs.SetInt("VerticalShots", (PlayerPrefs.GetInt("VerticalShots") + 1));
            }
        }

        //Decrease and update ammo.
        ammo--;
        Ammo.AmmoUpdate();

        //If out of ammo update achievements stats.
        if (ammo == 0)
        {
            PlayerPrefs.SetInt("RunOutAmmo", (PlayerPrefs.GetInt("RunOutAmmo") + 1));
        }

        //Update achievements stats.
        PlayerPrefs.SetInt("ShootTimes", (PlayerPrefs.GetInt("ShootTimes") + 1));

        //If gun shot was first disable bool.
        if (firstShot)
        {
            firstShot = false;
        }

        //Wait custom time to recoil.
        yield return(new WaitForSeconds(recoilTime));

        recoil = false;
    }