Example #1
0
    void Update()
    {
        var score = birdController.GetScore();

        scoreText.text = score.ToString();
    }
Example #2
0
    void Update()
    {
        switch (state)
        {
        case State.Tutorial:
            tutorialCanvas.SetActive(true);
            scoreCanvas.SetActive(false);
            gameOverCanvas.SetActive(false);

            birdBody.isKinematic = true;
            birdBody.velocity    = new Vector2(birdVelocity, 0.0f);

            float posY = birdPosY + birdAmplitude * Mathf.Sin(birdFrequency * Time.time);
            birdBody.position = new Vector2(birdBody.position.x, posY);

            if (Input.GetMouseButtonDown(0))
            {
                state = State.Game;
                birdBody.isKinematic = false;
                birdController.Flap();

                Object.Instantiate(pipePrefab, new Vector2(bird.transform.position.x + pipeHorizontalOffset, 0.0f), Quaternion.identity);
            }
            break;

        case State.Game:
            tutorialCanvas.SetActive(false);
            scoreCanvas.SetActive(true);
            gameOverCanvas.SetActive(false);

            if (Input.GetMouseButtonDown(0))
            {
                birdController.Flap();
            }
            birdController.KeepForwardVelocity(birdVelocity);

            var score = birdController.GetScore();
            scoreText.text         = score.ToString();
            gameOverScoreText.text = score.ToString();

            if (score > best)
            {
                best = score;
                PlayerPrefs.SetInt("Best", best);
            }

            gameOverBestText.text = best.ToString();

            if (!birdController.IsAlive())
            {
                state = State.Death;
            }
            break;

        case State.Death:
            tutorialCanvas.SetActive(false);
            scoreCanvas.SetActive(false);
            gameOverCanvas.SetActive(true);
            break;
        }
    }