示例#1
0
    void ListenSlide()
    {
        if (!sliding)
        {
            bool turningLeft  = false;
            bool turningRight = false;

            if (!moveLeft)
            {
                turningLeft = Input.GetKeyDown(KeyCode.LeftArrow) || TouchPadInput.GetButton("LeftArrow");
            }
            if (!moveRight)
            {
                turningRight = Input.GetKeyDown(KeyCode.RightArrow) || TouchPadInput.GetButton("RightArrow");
            }
            ;

            if (moveLeft)
            {
                if (moveLeft.isTouched())
                {
                    turningLeft = true;
                }
            }
            if (moveRight)
            {
                if (moveRight.isTouched())
                {
                    turningRight = true;
                }
            }

            if (turningLeft || turningRight)
            {
                toRotation = transform.rotation;

                if (turningLeft)
                {
                    toRotation *= Quaternion.Euler(0f, 0f, separationAngle);
                }
                else if (turningRight)
                {
                    toRotation *= Quaternion.Euler(0f, 0f, -separationAngle);
                }

                sliding = true;
                counter = 0;
            }
        }

        else
        {
            SlideBalls(SlideDirection.Right);
        }
    }
示例#2
0
    void BallJump()
    {
        if (ballState == BallState.Rolling)
        {
            bool inputJump = Input.GetKey(KeyCode.Space) || TouchPadInput.GetButton("Jump");

            if (ballGrounded && inputJump)
            {
                rb.AddForce(Vector3.up * ballSettings.jumpForce, ForceMode.VelocityChange);
            }

            Color groundedRayColor = Color.red;

            Ray        groundedRay = new Ray(transform.position, Vector3.down * bounds.extents.y);
            RaycastHit groundedHit;

            float adjustedextents = bounds.extents.y + 0.01f;

            if (Physics.Raycast(groundedRay, out groundedHit, adjustedextents))
            {
                Lane lane = groundedHit.collider.gameObject.GetComponent <Lane>();

                if (lane)
                {
                    groundedRayColor = Color.green;
                    ballGrounded     = true;
                }
            }
            else
            {
                ballGrounded = false;
            }

            Debug.DrawRay(transform.position, Vector3.down * adjustedextents, groundedRayColor);
        }
    }