Beispiel #1
0
    void Update()
    {
        if (CurrentState == GameState.Splash)
        {
            Splash.SetActive(true);
            if (Input.GetButtonDown("P1XboxX"))
            {
                ChangeState(GameState.Countdown);
            }
        }
        else if (CurrentState == GameState.Countdown)
        {
            if (!_isCountingDown)
            {
                Splash.SetActive(false);

                StartCoroutine(CountdownCoroutine());
            }
        }
        else if (CurrentState == GameState.Input)
        {
            if (!_isInputState)
            {
                _isInputState    = true;
                audioSource.clip = timerClip;
                audioSource.Play();

                Camera.backgroundColor = CurrentLevel.bgColor;

                PlayerImage.gameObject.SetActive(true);
                TargetImage.gameObject.SetActive(true);

                PlayerImage.rectTransform.position      = new Vector3(PlayerTransform.x * translateCoeff, PlayerTransform.y * translateCoeff, 0);
                PlayerImage.rectTransform.localRotation = Quaternion.Euler(0, 0, PlayerTransform.rotation * rotateCoeff);
                PlayerImage.rectTransform.localScale    = new Vector3(1, 1, 1) * PlayerTransform.scale * scaleCoeff;

                TargetImage.rectTransform.position      = new Vector3(TargetTransform.x * translateCoeff, TargetTransform.y * translateCoeff, 0);
                TargetImage.rectTransform.localRotation = Quaternion.Euler(0, 0, TargetTransform.rotation * rotateCoeff);
                TargetImage.rectTransform.localScale    = new Vector3(1, 1, 1) * TargetTransform.scale * scaleCoeff;

                UpdateSizeTexts();

                //TargetImage.color = CurrentLevel.bgColor * 0.9f;
                TargetImage.color = Color.white;
                PlayerImage.color = CurrentLevel.spriteColor;
                dotMaterial.color = PlayerImage.color;

                MyInput.Init();
            }

            var res = MyInput.Tick();
            if (res == InputTickResult.Confirm)
            {
                _isInputState = false;
                ChangeState(GameState.Play);
            }
            else if (res == InputTickResult.Timeout)
            {
                _isInputState = false;
                ChangeState(GameState.Lose);
                audioSource.Stop();
                audioSource.clip = loseClip;
                audioSource.Play();
            }
        }
        else if (CurrentState == GameState.Play)
        {
            if (!_isPlaying)
            {
                audioSource.Stop();
                audioSource.clip = silenceClip;
                audioSource.Play();

                var list = MyInput.myInputs;
                StartCoroutine(PlayCoroutine(list));
            }
        }
        else if (CurrentState == GameState.Transition)
        {
            CurrentLevelId++;
            LoadLevel(CurrentLevelId);
        }
        else if (CurrentState == GameState.Lose)
        {
            GameOverText.gameObject.SetActive(true);
            if (Input.GetButtonDown("P1XboxX"))
            {
                InitLevels();
                LoadLevel(0);
            }
        }
        else if (CurrentState == GameState.Win)
        {
            WinUI.gameObject.SetActive(true);
            if (Input.GetButtonDown("P1XboxX"))
            {
                InitLevels();
                LoadLevel(0);
            }
        }
    }