Esempio n. 1
0
    void Update()
    {
        transform.Rotate(new Vector3(0, 0, Time.deltaTime * speed * direction));

        if (Input.GetMouseButtonDown(0))
        {
            switch (gameState)
            {
            case GameState.START:
                direction = Random.Range(0, 2) == 0 ? -1 : 1;
                gameState = GameState.PLAYING;
                SpawnNewDot();
                dialogAlpha.FromStartToEnd();
                scoreAlpha.FromStartToEnd();
                break;

            case GameState.PLAYING:
                if (isNear)
                {
                    direction = -direction;
                    isClicked = true;
                    Destroy(GameObject.Find("Dot(Clone)").gameObject);
                    DecreaseScore();
                    if (currentScore == 0)
                    {
                        score++;
                        currentScore = score;

                        direction = 0;
                        gameState = GameState.WIN;
                        dialogAlpha.FromEndToStart();
                        dialogSystem.RandomWin();
                    }
                    else
                    {
                        SpawnNewDot();
                    }
                }
                else
                {
                    GameOver();
                }

                break;

            case GameState.OVER:
                transform.rotation = Quaternion.Euler(0, 0, 0);
                Destroy(GameObject.Find("Dot(Clone)").gameObject);
                gameState      = GameState.START;
                currentScore   = score;
                scoreText.text = currentScore.ToString();
                colorChanger.SetPreviousColor();
                break;

            case GameState.WIN:
                transform.rotation = Quaternion.Euler(0, 0, 0);
                gameState          = GameState.START;
                scoreText.text     = currentScore.ToString();
                colorChanger.SetNewColor();
                scoreAlpha.FromEndToStart();
                break;
            }
        }
    }