private void Update() { switch (playerController.health) { case 3: Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); break; case 2: Heart1.SetActive(false); Heart2.SetActive(true); Heart3.SetActive(true); break; case 1: Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(true); break; case 0: Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(false); break; } }
private void ChangeHealth() { #region 1. Избавляемся от громоздкого switch Heart1.SetActive(health > 0); Heart2.SetActive(health > 1); Heart3.SetActive(health > 2); #endregion #region 2. Переносим в массив for (int i = 0; i < Hearts.Count; i++) { Hearts[i].SetActive(health > i); } #endregion #region 3. Использование класса для отображения heartView.Display(health); #endregion #region 4. Перевод в событийную модель // На версии C#6 используйте сокращенную версию: // OnChangeHealth?.Invoke(health); // Я использую код, который подойдет для старых версий Unity и для C#4 if (OnChangeHealth != null) { OnChangeHealth(health); } #endregion }
void Start() { Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); health = 3; }
// Update is called once per frame void FixedUpdate() { if (internalHealth == 2) { Heart1.SetActive(false); Heart2.SetActive(true); Heart3.SetActive(true); } else if (internalHealth == 1) { Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(true); smoke.gameObject.SetActive(true); } if (internalHealth <= 0) { explodeSource.Play(); Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(false); this.gameObject.SetActive(false); Instantiate(explodeFrags, this.transform.position, this.transform.rotation); } }
void Update() { switch (health) { case 3: Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); break; case 2: Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(false); break; case 1: Heart1.SetActive(true); Heart2.SetActive(false); Heart3.SetActive(false); break; case 0: Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(false); break; } }
// Update is called once per frame void Update() { death = GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("death"); Appear = GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("appear"); Attack = GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Attack"); if (transform.position.x < xMin) { transform.position = new Vector3(xMin, transform.position.y, 0); } if (!death && !Appear && !Attack) { Movement(); } if (lives == 0) { if (!isRunning) { StartCoroutine(Death()); } } if (lives == 2) { Heart1.SetActive(false); } if (lives == 1) { Heart2.SetActive(false); } att = true; attack(); ScoreText.text = "" + Score; }
void Update() { if (Health.Value == 3f) { Heart3.SetActive(true); Heart2.SetActive(true); Heart1.SetActive(true); } if (Health.Value == 2f) { Heart3.SetActive(false); Heart2.SetActive(true); Heart1.SetActive(true); } if (Health.Value == 1f) { Heart3.SetActive(false); Heart2.SetActive(false); Heart1.SetActive(true); } if (Health.Value <= 0f) { Heart3.SetActive(false); Heart2.SetActive(false); Heart1.SetActive(false); } }
// Update is called once per frame void Update() { //if (scoreIncreasing) { // scoreCounts += pointPerSecond * Time.deltaTime; //} //extra heart indicator if ((heartCounterText != null) && (HeartCount > 3)) { //heartCounterText.GetComponent<Text>().enabled = true; heartCounterText.GetComponent <Text>().text = "x" + HeartCount; } else { heartCounterText.GetComponent <Text>().text = ""; } if (scoreCounts > highScoreCounts) { highScoreCounts = scoreCounts; PlayerPrefs.SetFloat("HighScores", highScoreCounts); } scoreText.text = "Coins: " + Mathf.Round(scoreCounts); highScoreText.text = "High Score: " + Mathf.Round(highScoreCounts); gameScore.text = "" + Mathf.Round(gameScoreCounts); if (HeartCount == 3) { Heart3.SetActive(true); Heart2.SetActive(false); Heart1.SetActive(false); Heart0.SetActive(false); } else if (HeartCount == 2) { Heart3.SetActive(false); Heart2.SetActive(true); Heart1.SetActive(false); Heart0.SetActive(false); } else if (HeartCount == 1) { Heart3.SetActive(false); Heart2.SetActive(false); Heart1.SetActive(true); Heart0.SetActive(false); } else if (HeartCount == 0) { HeartCount = 3; Heart3.SetActive(false); Heart2.SetActive(false); Heart1.SetActive(false); Heart0.SetActive(true); gameManager.RestartGame(); } }
void Start() { health = 4; Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); Heart4.SetActive(true); gameOver.SetActive(false); Restart.SetActive(false); MainMenu.SetActive(false); Quit.SetActive(false); }
public void Play_Start_Click(object sender, EventArgs e) // Function switches on a game { LevelUpGif.BringToFront(); if (firstPlane) { Heart1.Visible = true; Heart2.Visible = true; Heart3.Visible = true; } else if (secondPlane) { this.Controls.Remove(Heart1); Heart1.Dispose(); Heart2.Visible = true; Heart3.Visible = true; } else if (thirdPlane) { this.Controls.Remove(Heart1); Heart1.Dispose(); this.Controls.Remove(Heart2); Heart2.Dispose(); Heart3.Visible = true; } if (isstarted) { if (paused) { StartTimers(); Menu_Off(); } } if (!isstarted) { isstarted = true; Menu_Off(); Player.Visible = true; Change_Off.Visible = false; PointsLabel.Visible = true; StarsMoveTimer.Start(); for (int i = 0; i < stars.Length; i++) { stars[i].Visible = true; } enemyMoveTimer.Start(); } }
//everytime the player gets hit a hearth is gone void Update() { if (health > 4) { health = 4; } switch (health) { case 4: Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); Heart4.SetActive(true); break; case 3: Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); Heart4.SetActive(false); break; case 2: Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(false); Heart4.SetActive(false); break; case 1: Heart1.SetActive(true); Heart2.SetActive(false); Heart3.SetActive(false); Heart4.SetActive(false); break; case 0: Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(false); Heart4.SetActive(false); // UI interface when the game is over gameOver.SetActive(true); Restart.SetActive(true); MainMenu.SetActive(true); MainMenu.SetActive(true); Time.timeScale = 0; health = 4; break; } }
public void ReviveHearths() { Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); for (int i = 0; i < 3; i++) { currentHeart = GameObject.Find("Heart" + i); iTween.MoveAdd(currentHeart, iTween.Hash("amount", new Vector3(0, -5f, 0), "time", 2f, "easytype", iTween.EaseType.linear, "looptype", iTween.LoopType.none)); iTween.FadeTo(currentHeart, iTween.Hash("alpha", 1f, "time", 0.1f, "easytype", iTween.EaseType.linear, "looptype", iTween.LoopType.none)); } StartCoroutine(FadeInUI()); }
public void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Slime" || col.gameObject.tag == "Snake" || col.gameObject.tag == "Boot") { Lives--; if (Lives < 1) { Heart1.GetComponent <SpriteRenderer>().enabled = false; Menu.GetComponent <mainMenuJump>().BringUpMenu(); } else if (Lives < 2) { Heart2.GetComponent <SpriteRenderer>().enabled = false; } else if (Lives < 3) { Heart3.GetComponent <SpriteRenderer>().enabled = false; } } }
void RestarVida(int vida) { Rigidbody rb = this.GetComponent <Rigidbody>(); if (vida == 1) { Heart1.SetActive(false); rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); PlayerController.balaAgarrada = false; } else if (vida == 2) { Heart2.SetActive(false); rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); PlayerController.balaAgarrada = false; } else if (vida == 3) { Heart3.SetActive(false); rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); PlayerController.balaAgarrada = false; } else if (vida == 4) { Heart4.SetActive(false); rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); Player2Controller.balaAgarrada = false; } else if (vida == 5) { Heart5.SetActive(false); rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); Player2Controller.balaAgarrada = false; } else if (vida == 6) { Heart6.SetActive(false); rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); Player2Controller.balaAgarrada = false; } }
public void OnTriggerEnter(Collider col) { if (col.tag == "Obstacle" || col.tag == "Bomb") { Lives--; this.gameObject.GetComponent <AudioSource>().Play(); if (Lives < 1) { Heart1.GetComponent <SpriteRenderer>().enabled = false; Menu.GetComponent <mainMenuJump>().BringUpMenu(); } else if (Lives < 2) { Heart2.GetComponent <SpriteRenderer>().enabled = false; } else if (Lives < 3) { Heart3.GetComponent <SpriteRenderer>().enabled = false; } } }
public void UpdateHealth(int currentHealth, int maxHealth) { float percentage = currentHealth / (float)maxHealth; if (percentage >= 1f) { Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); Heart4.SetActive(true); } else if (percentage >= 0.75f) { Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(true); Heart4.SetActive(false); } else if (percentage >= 0.5f) { Heart1.SetActive(true); Heart2.SetActive(true); Heart3.SetActive(false); Heart4.SetActive(false); } else if (percentage >= 0.25f) { Heart1.SetActive(true); Heart2.SetActive(false); Heart3.SetActive(false); Heart4.SetActive(false); } else { Heart1.SetActive(false); Heart2.SetActive(false); Heart3.SetActive(false); Heart4.SetActive(false); } }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Slime" || col.gameObject.tag == "Boot" || col.gameObject.tag == "Snake") { audioSource = GetComponent <AudioSource>(); audioSource.clip = sound; audioSource.Play(); Lives--; if (Lives < 1) { Heart1.GetComponent <SpriteRenderer>().enabled = false; Menu.GetComponent <mainMenuJump>().BringUpMenu(); } else if (Lives < 2) { Heart2.GetComponent <SpriteRenderer>().enabled = false; } else if (Lives < 3) { Heart3.GetComponent <SpriteRenderer>().enabled = false; } } }
public void SwitchChoice(int x) { if (x == 10) //Enter { if (chosenNumber.Count > 0 && chosenSymbol.Count > 0 && chosenColor.Count > 0) //make sure they arent empty { // print(conversion(chosenColor.ElementAt(0))); // print(conversionSymbol(chosenSymbol.ElementAt(0))); if ((chosenNumber.ElementAt(0)).ToString() == God.number && conversion(chosenColor.ElementAt(0)) == God.color && conversionSymbol(chosenSymbol.ElementAt(0)) == God.symbol) { WinnerMenu.GetComponent <jumpToBoss>().BringUpMenu(); } else { Lives--; if (Lives < 1) { GameObject.Find("Directional Light").GetComponent <AudioSource>().Play(); Heart1.GetComponent <SpriteRenderer>().enabled = false; Menu.GetComponent <mainMenuJump>().BringUpMenu(); return; } else if (Lives < 2) { GameObject.Find("Directional Light").GetComponent <AudioSource>().Play(); Heart2.GetComponent <SpriteRenderer>().enabled = false; return; } else if (Lives < 3) { GameObject.Find("Directional Light").GetComponent <AudioSource>().Play(); Heart3.GetComponent <SpriteRenderer>().enabled = false; return; } } } else { // print("retuned"); return; } GameObject.Find("ChosenOnes").GetComponent <AudioSource>().Play(); /* * if(chosenNumber.Count > 0) * { * chosenNumber.RemoveAt(chosenNumber.Count - 1); * } * if(chosenSymbol.Count > 0) * { * chosenSymbol.RemoveAt(chosenSymbol.Count - 1); * } * if(chosenColor.Count > 0) * { * chosenColor.RemoveAt(chosenColor.Count - 1); * } */ } else if (x < 3) //Left Column { for (int i = 0; i < 3; i++) { pressed.ElementAt(i).GetComponent <SpriteRenderer>().enabled = false; if (chosenNumber.Count > 0) { chosenNumber.RemoveAt(chosenNumber.Count - 1); } } pressed.ElementAt(x).GetComponent <SpriteRenderer>().enabled = true; chosenNumber.Add(x); } else if (x >= 3 && x <= 5) //Middle Column { for (int i = 3; i <= 5; i++) { pressed.ElementAt(i).GetComponent <SpriteRenderer>().enabled = false; if (chosenSymbol.Count > 0) { chosenSymbol.RemoveAt(chosenSymbol.Count - 1); } } pressed.ElementAt(x).GetComponent <SpriteRenderer>().enabled = true; chosenSymbol.Add(x); } else { for (int i = 6; i < 9; i++) //Right Column { pressed.ElementAt(i).GetComponent <SpriteRenderer>().enabled = false; if (chosenColor.Count > 0) { chosenColor.RemoveAt(chosenColor.Count - 1); } } pressed.ElementAt(x).GetComponent <SpriteRenderer>().enabled = true; chosenColor.Add(x); } }
public void EnemyBulletsCollision() { for (int i = 0; i < enemies.Count; i++) { if (thirdPlane && enemies[i].EnemyBullet.EnemyBulletPicture != null && enemies[i].EnemyBullet.EnemyBulletPicture.Bounds.IntersectsWith(Player.Bounds)) { //destruction of the third heart //gameover enemies[i].EnemyBullet.death(); this.Controls.Remove(Heart3); Heart3.Dispose(); gameover(); } else if (secondPlane && enemies[i].EnemyBullet.EnemyBulletPicture != null && enemies[i].EnemyBullet.EnemyBulletPicture.Bounds.IntersectsWith(Player.Bounds)) { HeatCount++; Player.Location = new Point(313, 570); enemies[i].EnemyBullet.death(); if (HeatCount == 1) { //destruction of the second heart this.Controls.Remove(Heart2); Heart2.Dispose(); } else if (HeatCount == HP) { //destruction of the Third heart //gameover this.Controls.Remove(Heart3); Heart3.Dispose(); gameover(); } } else if (firstPlane && enemies[i].EnemyBullet.EnemyBulletPicture != null && enemies[i].EnemyBullet.EnemyBulletPicture.Bounds.IntersectsWith(Player.Bounds)) { HeatCount++; Player.Location = new Point(313, 570); enemies[i].EnemyBullet.death(); if (HeatCount == 1) { //destruction of the first heart this.Controls.Remove(Heart1); Heart1.Dispose(); } else if (HeatCount == 2) { //destruction of the second heart this.Controls.Remove(Heart2); Heart2.Dispose(); } else if (HeatCount == HP) { //destruction of the third heart //gameover this.Controls.Remove(Heart3); Heart3.Dispose(); gameover(); } } } }