Пример #1
0
 void Start()
 {
     Heart1.SetActive(true);
     Heart2.SetActive(true);
     Heart3.SetActive(true);
     health = 3;
 }
Пример #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
 }
    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;
        }
    }
Пример #4
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;
        }
    }
Пример #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;
    }
Пример #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;
        }
    }
Пример #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());
    }
Пример #10
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;
        }
    }
Пример #11
0
    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);
        }
    }