Beispiel #1
0
    public void UpdateHealth(float amount, Vector3 pos)
    {
        if (duel == 0)
        {
            if (gameOver == false)
            {
                health += amount;

                if (health > 1)
                {
                    health = 1;
                }

                healthBarFill.fillAmount = health;
                //green -= 10;
                healthBarFill.color = new Color(1, health, 0, 1);

                if (amount < 0)
                {
                    healthBarAnimator.Play("ShakeHealthBar", -1, 0f);
                }

                if (health <= 0)
                {
                    gameOver = true;

                    playButton.GameOver();
                    //leftSpawner.CloseTextFile();
                    //rightSpawner.CloseTextFile();
                    ScoreManager.Instance.UpdateHighScore();
                    if (leftSpawner != null)
                    {
                        leftSpawner.CloseTextFile();
                        rightSpawner.CloseTextFile();
                    }
                }
            }
        }
        else
        {
            if (pos.x < 0)
            {
                if (gameOver == false)
                {
                    health += amount;

                    if (health > 1)
                    {
                        health = 1;
                    }

                    healthBarFill.fillAmount = health;
                    //green -= 10;
                    healthBarFill.color = new Color(1, health, 0, 1);

                    if (amount < 0)
                    {
                        healthBarAnimator.Play("ShakeHealthBar", -1, 0f);
                    }

                    if (health <= 0)
                    {
                        gameOver = true;
                        if (health1 != 0)
                        {
                            winText.text = "RIGHT WINS";
                            winText.GetComponent <Animator>().Play("timerStart");
                        }
                        else
                        {
                            winText.text = "DRAW";
                            winText.GetComponent <Animator>().Play("timerStart");
                        }
                        playButton.GameOver();
                        //leftSpawner.CloseTextFile();
                        //rightSpawner.CloseTextFile();
                        ScoreManager.Instance.UpdateHighScore();
                        if (leftSpawner != null)
                        {
                            leftSpawner.CloseTextFile();
                            rightSpawner.CloseTextFile();
                        }
                    }
                }
            }
            else
            {
                if (gameOver == false)
                {
                    health1 += amount;

                    if (health1 > 1)
                    {
                        health1 = 1;
                    }

                    healthBarFill1.fillAmount = health1;
                    //green -= 10;
                    healthBarFill1.color = new Color(1, health1, 0, 1);

                    if (amount < 0)
                    {
                        healthBarAnimator1.Play("ShakeHealthBar", -1, 0f);
                    }

                    if (health1 <= 0)
                    {
                        gameOver = true;
                        if (health != 0)
                        {
                            winText.text = "LEFT WINS";
                            winText.GetComponent <Animator>().Play("timerStart");
                        }
                        else
                        {
                            winText.text = "DRAW";
                            winText.GetComponent <Animator>().Play("timerStart");
                        }
                        playButton.GameOver();
                        //leftSpawner.CloseTextFile();
                        //rightSpawner.CloseTextFile();
                        ScoreManager.Instance.UpdateHighScore();
                        if (leftSpawner != null)
                        {
                            leftSpawner.CloseTextFile();
                            rightSpawner.CloseTextFile();
                        }
                    }
                }
            }
        }
    }