void Update() { //Display score to device. scoreTxt.text = ((int)transform.position.y / 2).ToString(); //If higscore is reached then spawn highscore line. if (highscoreReached && (int)transform.position.y / 2 == highScore - 10) { LayersSpawn.SpawnHighscoreLine(); highscoreReached = false; } //If playing in challenge mode. if (ChallengeMenu.challengeActive[0]) { Coroutines.AchieveChallenge((int)transform.position.y / 2, 25, 50, 100); } //If playing in challenge mode. else if (ChallengeMenu.challengeActive[4]) { if (GunCollider.boosterUsed) { lastCount = (int)transform.position.y / 2; GunCollider.boosterUsed = false; } scoreCount = (int)transform.position.y / 2 - lastCount; Coroutines.AchieveChallenge(scoreCount, 25, 50, 100); } //Change background color. if (!change && (int)transform.position.y / 2 > 1 && (int)transform.position.y / 2 % 50 == 0) { //Create random color. newColor.r = (byte)(Random.Range(0, 20)); newColor.g = (byte)(Random.Range(0, 20)); newColor.b = (byte)(Random.Range(0, 20)); timer = 0; change = true; } if (timer >= 2) { change = false; } if (timer < 2) { //Lerp background color from old to new. transform.GetComponent <Camera>().backgroundColor = Color.Lerp(transform.GetComponent <Camera>().backgroundColor, newColor, timer); timer += Time.deltaTime; } }
void OnTriggerEnter2D(Collider2D col) { //If gun touched coin. if (col.tag == "GunUI") { //Add coin to wallet. Wallet.AddCoins(1); //Add coin to Achievements stats. PlayerPrefs.SetInt("CollectCoins", (PlayerPrefs.GetInt("CollectCoins") + 1)); coinCount++; //If collected 10 coins in one session then first achievement has been reached. if (coinCount == 10 && PlayerPrefs.GetInt("OneSessionCoins") < 10) { PlayerPrefs.SetInt("OneSessionCoins", 10); } //If collected 10 coins in one session then second achievement has been reached. else if (coinCount == 25 && PlayerPrefs.GetInt("OneSessionCoins") < 25) { PlayerPrefs.SetInt("OneSessionCoins", 25); } //If collected 10 coins in one session then third achievement has been reached. else if (coinCount == 50 && PlayerPrefs.GetInt("OneSessionCoins") < 50) { PlayerPrefs.SetInt("OneSessionCoins", 50); } //If playing in challenge mode. if (ChallengeMenu.challengeActive[3]) { //Update challenge stats. Coroutines.AchieveChallenge(coinCount, 25, 50, 100); } //Start destroy coroutine. StartCoroutine(CoinDestroy()); } }
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; } }
void OnTriggerEnter2D(Collider2D col) { //If gun enters left side collider then second gun position changes to the right side. if (col.tag == "LSide") { transform.position = new Vector2(clonePos.position.x + 5.64f, transform.position.y); } //If gun enters right side collider then second gun position changes to the left side. if (col.tag == "RSide") { transform.position = new Vector2(clonePos.position.x - 5.64f, transform.position.y); } //If gun touch speed object. if (col.tag == "Speed") { //Gun gets flying up boost. Gun.speedUp = true; #if UNITY_ANDROID //Device vibrates. if (SettingsMenu.vibration == 1) { Vibration.Vibrate(50); } #endif //If challenge mode. if (ChallengeMenu.challengeActive[2]) { //Adding boosters count. boosterCount++; //Updating challenge stats. Coroutines.AchieveChallenge(boosterCount, 5, 15, 25); } //If challenge mode. if (ChallengeMenu.challengeActive[4]) { //Enabling booster bool. boosterUsed = true; } //Adding how many boosters has been used to achievements. PlayerPrefs.SetInt("CollectSpeed", (PlayerPrefs.GetInt("CollectSpeed") + 1)); } //If gun touched bullet. if (col.tag == "Bullet") { //Gun is reloaded. Gun.reload = true; //Adding how many bullets has been used to achievements. PlayerPrefs.SetInt("CollectBullets", (PlayerPrefs.GetInt("CollectBullets") + 1)); //If in challenge mode. if (ChallengeMenu.challengeActive[5]) { //Adding bullet count. bulletCount++; //Updating challenge stats. Coroutines.AchieveChallenge(bulletCount, 5, 15, 25); } } if (col.tag == "Blocker") { Gun.ResetForces(); #if UNITY_ANDROID //If vibrate is on vibrate device. if (SettingsMenu.vibration == 1) { Vibration.Vibrate(50); } #endif //Start shaking camera. StartCoroutine(CameraShake.Shake(0.1f, 0.2f)); } //If gun reached bottom side collider then gun gameobject is disabled. if (col.tag == "BSide") { transform.parent.gameObject.SetActive(false); } }