示例#1
0
    private void Update()
    {
        if (!isTouchActive)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            prevPosition   = Input.mousePosition;
            targetPosition = holeTransform.position;
        }

        if (Input.GetMouseButton(0))
        {
            Vector3 touchDelta    = Input.mousePosition - prevPosition;                                                                                                                 // screen touch delta
            Vector3 positionDelta = touchDelta * pixelToPlayground * touchSens;                                                                                                         // world touch delta
            positionDelta = new Vector3(positionDelta.x, 0f, positionDelta.y * heightToWidthCoef);                                                                                      // normalized world delta

            targetPosition = targetPosition + positionDelta;                                                                                                                            // target position

            targetPosition = new Vector3(Mathf.Clamp(targetPosition.x, leftBound, rightBound), 0f, Mathf.Clamp(targetPosition.z, bottomBound + stageOffsetZ, topBound + stageOffsetZ)); // clamped to playground bounds

            holeTransform.position = Vector3.Lerp(holeTransform.position, targetPosition, 0.3f);                                                                                        // lerped position

            GroundGenerator.UpdateGround();

            prevPosition = Input.mousePosition;
        }
    }
示例#2
0
    private IEnumerator MoveHoleToNextStage(Transform holeTransform)
    {
        TouchController.instance.Deactivate();
        DeactivateFirstStageObstacles();
        OpenGates();

        float playgroundCenter   = GroundGenerator.PlaygroundCenter;
        WaitForFixedUpdate delay = new WaitForFixedUpdate();

        while (Mathf.Abs(holeTransform.position.x - playgroundCenter) > 0.01f)
        {
            holeTransform.position = Vector3.MoveTowards(holeTransform.position, holeTransform.position.SetX(playgroundCenter), 2f * Time.fixedDeltaTime);
            GroundGenerator.UpdateGround();

            yield return(delay);
        }

        HoleBehabiour.EnableAroundHoleMesh();
        holeTransform.position = holeTransform.position.SetX(playgroundCenter);

        float nextStageStartZ = GroundGenerator.PLAYGROUND_HEIGHT + GroundGenerator.GROUNDS_OFFSET + GroundGenerator.HOLE_INITIAL_OFFSET_Z;

        CameraController.instance.MoveToSecondStage();
        GroundGenerator.stopVerticalMeshGen = true;

        while (Mathf.Abs(holeTransform.position.z - nextStageStartZ) > 0.01f)
        {
            holeTransform.position = Vector3.MoveTowards(holeTransform.position, holeTransform.position.SetZ(nextStageStartZ), 4f * Time.fixedDeltaTime);
            GroundGenerator.UpdateGround();

            GroundGenerator.UpdateConnectingPath();

            yield return(delay);
        }

        ActivateFirstStageObstacles();
        HoleBehabiour.DisableAroundHoleMesh();
        GameController.OnSecondStageReached();

        GroundGenerator.stopVerticalMeshGen = false;
        GroundGenerator.RecalculateNormals();
        GroundGenerator.UpdateGround();
    }