Esempio n. 1
0
    // Update is called once per frame.
    void Update()
    {
        // The moment the player stops touching the ground they lose the game and go to the game over menu.
        if (!IsGrounded() && IsPlaying)
        {
            isDead = true;
            // Stops the camera from moving and tiles from falling.
            IsPlaying = false;
            // Loads the Game Over function and reset button.
            myMenuScript.GameOver();

            resetBtn.SetActive(true);

            if (transform.childCount > 0)
            {
                transform.GetChild(0).transform.parent = null;
            }
        }

        // Triggered when the played clicks and is not dead, therefore when they are playing the game.
        if (Input.GetMouseButtonDown(0) && !isDead)
        {
            IsPlaying = true;
            score++;
            scoreUI.SetText(score.ToString());
            // On the first tap it should remove the Game Start menu.
            if (myMenuScript.firstTap == false)
            {
                myMenuScript.FirstTap();
            }

            // If the player is moving forward it will set the direction to the left, if it is facing any other direction it will set the direction to forward.
            // This is the function that causes it to switch between two directions.
            if (dir == Vector3.forward)
            {
                dir = Vector3.left;
            }
            else
            {
                dir = Vector3.forward;
            }
        }

        // Actually moves the sphere in the set direction at a constant speed.
        float amountToMove = speed * Time.deltaTime;

        transform.Translate(dir * amountToMove);
    }