コード例 #1
0
 public void OnMaskClick()
 {
     if (_isLose)
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }
     else
     {
         _birdController.Flap();
     }
 }
コード例 #2
0
    void GameStart()
    {
        state = State.Play;

        bird.SetSteerAction(true);
        blocks.SetActive(true);

        bird.Flap();

        stateLabel.gameObject.SetActive(false);
        stateLabel.text = "";
    }
コード例 #3
0
    private void Update()
    {
        if (IsFlapKeyPressed())
        {
            // If this is the first flap, set the flag to true
            if (!hasStartedFlapping)
            {
                hasStartedFlapping = true;

                // Start the pipes
                pipeSpawner.StartSpawningPipes();
            }

            Debug.Log("Flap!");
            birdController.Flap();
        }
    }
コード例 #4
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;
        }
    }