Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (startButton.IsActive())
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                onClick();
            }
        }

        if (gameOver)
        {
            if (DebugMode)
            {
                Debug.Log("Game over.");
            }
            actionText.text = "GAME OVER!";
            startButton.gameObject.SetActive(true);

            return;
        }

        int numOfActions = Enum.GetNames(typeof(Action)).Length;

        if (gameStarted)
        {
            timePassed += Time.deltaTime;
            if (timePassed > currentSpeed)
            {
                successText.gameObject.SetActive(false);

                if (!isLastActionPressed)
                {
                    healthBarScale -= healthBarScaleChange;

                    healthBar.transform.localScale = new Vector3(healthBarScale, healthBar.transform.localScale.y);

                    if (healthBarScale <= 0)
                    {
                        gameOver = true;
                        return;
                    }
                }
                isLastActionPressed = false; //reset action pressed.

                Action randomAction = (Action)random.Next(0, numOfActions);

                IAction newAction;
                switch (randomAction)
                {
                case Action.Jump:
                    newAction = new Jump();
                    break;

                case Action.Dance:
                    newAction = new Dance();
                    break;

                case Action.Color:
                    newAction = new Color();
                    break;

                default:
                    throw new Exception("Fatal error.");
                }

                actionText.gameObject.SetActive(true);

                newAction.Activate();
                latestAction = newAction;

                timePassed = 0.0f;

                if (currentSpeed > MinSpeed)
                {
                    currentSpeed *= (1 - SpeedChangePercentage / 100);
                }

                if (DebugMode)
                {
                    //Debug.Log($"Current speed: {currentSpeed}");
                }
                //actionsStack.Enqueue(newAction);
            }
            else
            {
                if (latestAction != null &&
                    !isLastActionPressed &&
                    latestAction.CheckInput())
                {
                    actionText.gameObject.SetActive(false);
                    successText.gameObject.SetActive(true);
                    isLastActionPressed = true;
                    IncrementScore();
                }
            }
        }
    }