Ejemplo n.º 1
0
    public void GameOver()
    {
        Debug.LogError("game over");
        GameConst.instance.isGameOn = false;

        secondChance.gameObject.SetActive(false);

        //Time.timeScale = 0;

        if (DataScript.isGameModeEndless == 0)
        {
            DataScript.isSessionEnded = true;
            DataScript.pointHolder    = 0;
            DataScript.isSecondChanceButtonPushedForLevel = false;
            DataScript.isPassedAtLeastOneLevel            = false;
        }

        gameOverPanel.SetActive(true);

        StopAllCoroutines();

        GameConst.playedTime++;
        PlayerPrefs.SetInt("PlayedTime", GameConst.playedTime);

        if (!DataScript.isAdsPurchased)
        {
            if (PlayerPrefs.GetInt("PlayedTime") % 5 == 0 && !GameConst.instance.secondPushed)
            {
                ads.ShowAd();
            }
        }
        setGoldText();
        goldCounterText.gameObject.SetActive(true);

        if (DataScript.isGameModeEndless == 1)
        {
            if (GameConst.instance.points > highScore)
            {
                PlayerPrefs.SetInt("highScore", GameConst.instance.points);
                highScore = GameConst.instance.points;
                highScorePoint.gameObject.SetActive(false);
                highScoreText.gameObject.SetActive(false);
                newHighScoreMade.gameObject.SetActive(true);
            }
            else
            {
                highScore           = PlayerPrefs.GetInt("highScore", highScore);
                highScoreText.text  = "High Score";
                highScorePoint.text = highScore.ToString();
                highScorePoint.gameObject.SetActive(true);
                highScoreText.gameObject.SetActive(true);
                newHighScoreMade.gameObject.SetActive(false);
            }
        }
        else
        {
            if (GameConst.instance.points > highScore)
            {
                PlayerPrefs.SetInt("LevelHighScore", GameConst.instance.points);
                highScore = GameConst.instance.points;
                highScorePoint.gameObject.SetActive(false);
                highScoreText.gameObject.SetActive(false);
                newHighScoreMade.gameObject.SetActive(true);
            }
            else
            {
                highScore           = PlayerPrefs.GetInt("LevelHighScore", highScore);
                highScoreText.text  = "High Score";
                highScorePoint.text = highScore.ToString();
                highScorePoint.gameObject.SetActive(true);
                highScoreText.gameObject.SetActive(true);
                newHighScoreMade.gameObject.SetActive(false);
            }
        }
        pointCounterText.gameObject.SetActive(false);

        energySlider.gameObject.SetActive(false);
        restartButton.gameObject.SetActive(true);
    }