コード例 #1
0
    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);
        }
    }
コード例 #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
 }
コード例 #3
0
 // 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;
 }
コード例 #4
0
    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;
        }
    }
コード例 #5
0
 void Start()
 {
     Heart1.SetActive(true);
     Heart2.SetActive(true);
     Heart3.SetActive(true);
     health = 3;
 }
コード例 #6
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;
        }
    }
コード例 #7
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);
        }
    }
コード例 #8
0
    // 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();
        }
    }
コード例 #9
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);
 }
コード例 #10
0
    //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;
        }
    }
コード例 #11
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());
    }
コード例 #12
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;
        }
    }
コード例 #13
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);
        }
    }