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;
        }
    }
Example #2
0
 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
 }
Example #3
0
    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;
        }
    }
Example #4
0
 void Start()
 {
     Heart1.SetActive(true);
     Heart2.SetActive(true);
     Heart3.SetActive(true);
     health = 3;
 }
Example #5
0
    // 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);
        }
    }
    public IEnumerator Death()
    {
        isRunning = true;
        Heart3.SetActive(false);
        GetComponent <Animator>().SetInteger("animate", 3);
        yield return(new WaitForSeconds(GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length + 0.1f));

        Time.timeScale = 0;
        UI.SetActive(true);
        isRunning = false;
    }
Example #7
0
 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);
 }
    //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;
        }
    }
Example #9
0
    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());
    }
Example #10
0
 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;
         }
     }
 }
Example #11
0
    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;
        }
    }
Example #12
0
 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);
        }
    }
Example #14
0
 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;
         }
     }
 }
Example #15
0
    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);
        }
    }
Example #16
0
        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();
                    }
                }
            }
        }