Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            GotoMenu();
        }

        switch (gameState)
        {
        case GameState.Countdown:
            countdownTimer -= Time.deltaTime;
            if (countdownTimer < 0)
            {
                countdownInt      -= 1;
                countdownTimer    += 1f;
                countDownText.text = countdownInt.ToString();
                if (countdownInt > 0)
                {
                    SoundManager.PlaySound(countSound);
                }
            }

            if (countdownInt < 1)
            {
                SoundManager.PlaySound(startSound);
                gameState = GameState.Play;
                countDownText.gameObject.SetActive(false);
                timerText.gameObject.SetActive(true);
                player.Activate();
            }
            break;

        case GameState.Play:
            elapsedTime   += Time.deltaTime;
            timerText.text = string.Format("{0:F1}", elapsedTime);
            break;

        case GameState.Finish:
            if (nameInput.isFocused && Input.GetKeyDown(KeyCode.Return))
            {
                OnConfirmName();
            }
            break;

        case GameState.Leaderboard:
            MenuManager.GetLeaderboardString(leaderBoard);
            break;

        default:
            throw new UnityException("Bad");
        }
    }