Example #1
0
    private void Start()
    {
        BallCurrentState = State.Still;
        BallThrowPower   = ThrowPower.NoPower;

        moveBallScript  = gameObject.GetComponent <MoveBall>();
        throwBallScript = gameObject.GetComponent <ThrowBall>();

        rb = gameObject.GetComponent <Rigidbody>();
        stickCollisionScript = GameObject.Find("Stick").GetComponent <Stick>();

        maxDistance = 49.51f;

        finishCollider = GameObject.Find("Finish Collider").GetComponent <FinishCollider>();
    }
Example #2
0
    private void Update()
    {
        #region Ball's Progression

        if (BallCurrentState == State.Still)
        {
            if (maxReach < transform.position.y - 0.49f)
            {
                if (maxReach < maxDistance)
                {
                    maxReach = transform.position.y - 0.49f;
                }
                else
                {
                    maxReach = maxDistance;
                }

                GameManager.Score = (int)(maxReach * 9);
            }
        }

        #endregion

        #region Ball State Descriptions

        if (BallCurrentState == State.Still)
        {
            BallThrowPower = ThrowPower.NoPower;

            moveBallScript.enabled  = true;
            throwBallScript.enabled = false;
            stickMesh.SetActive(true);
        }

        else if (BallCurrentState == State.Thrown)
        {
            moveBallScript.enabled  = false;
            throwBallScript.enabled = true;
            stickMesh.SetActive(false);

            #region Ball's Touch Control In Air

            //if player taps while the ball is on platform, change ball state to still.
            if (stickCollisionScript.isOnPlatform)
            {
                if (!finishCollider.didBallCollided)
                {
                    if (Input.touchCount > 0)
                    {
                        touch = Input.GetTouch(0);

                        if (touch.phase == TouchPhase.Began)
                        {
                            BallCurrentState = State.Still;
                        }
                    }
                }
                //if the ball passed the finish line
                else
                {
                    //We let player touch one time and then ball gets freeze and fall state.
                    if (Input.touchCount > 0)
                    {
                        touch = Input.GetTouch(0);

                        if (touch.phase == TouchPhase.Began)
                        {
                            StartCoroutine(FreezeAndFall());
                        }
                    }
                }
            }

            #endregion
        }

        else if (BallCurrentState == State.Freeze)
        {
            BallThrowPower = ThrowPower.NoPower;

            moveBallScript.enabled  = false;
            throwBallScript.enabled = false;
            stickMesh.SetActive(true);
        }

        else if (BallCurrentState == State.Falling)
        {
            BallThrowPower = ThrowPower.NoPower;

            moveBallScript.enabled  = false;
            throwBallScript.enabled = false;
            stickMesh.SetActive(false);
        }

        #endregion
    }