예제 #1
0
    //void HandleTunnelMove()
    //{
    //    Vector3 mapPos = MapSpawner.Instance.GetCurrentMapHolder().transform.position;

    //    if (currentTopObjectYpos > mapPos.y)
    //    {
    //        // if (!isGoingDown) ReverseQueue();

    //        GameObject pieceToMove = tunnelPieces.Dequeue();

    //        Vector3 targetPos = new Vector3(mapPos.x, currentTopObjectYpos - (distanceBetweenObjects * (numberOfObjects - 1)), mapPos.z);
    //        IEnumerator coroutine = MoveTo(pieceToMove, targetPos, 2f);
    //        StartCoroutine(coroutine);

    //        currentBottomObjectYpos = pieceToMove.transform.position.y;
    //        currentTopObjectYpos -= distanceBetweenObjects;
    //        tunnelPieces.Enqueue(pieceToMove);
    //    }
    //}

    void HandleTunnelMove()
    {
        Vector3 mapPos = MapSpawner.Instance.GetCurrentMapHolder().transform.position;

        Vector3 targetPos;


        if (isGoingDown) // Going Down
        {
            if (currentTopObjectYpos < mapPos.y /*- distanceBetweenObjects*/)
            {
                /*tunnelPieces = */
                ReverseQueueUtil <GameObject> .ReverseQueue(ref tunnelPieces);

                isGoingDown = !isGoingDown;
                return;
            }

            if (currentTopObjectYpos > mapPos.y)
            {
                GameObject pieceToMove = tunnelPieces.Dequeue();
                targetPos = new Vector3(mapPos.x, currentTopObjectYpos - (distanceBetweenObjects * (numberOfObjects - 1)), mapPos.z);
                IEnumerator coroutine = MoveTo(pieceToMove, targetPos, 2f);
                StartCoroutine(coroutine);
                currentBottomObjectYpos = targetPos.y;
                currentTopObjectYpos   -= distanceBetweenObjects;
                tunnelPieces.Enqueue(pieceToMove);
            }
        }
        else // Going Up
        {
            if (currentTopObjectYpos > mapPos.y + distanceBetweenObjects)
            {
                /*tunnelPieces = */
                ReverseQueueUtil <GameObject> .ReverseQueue(ref tunnelPieces);

                isGoingDown = !isGoingDown;
                return;
            }

            if (currentTopObjectYpos < mapPos.y - distanceBetweenObjects)
            {
                GameObject pieceToMove = tunnelPieces.Dequeue();
                targetPos = new Vector3(mapPos.x, currentTopObjectYpos + distanceBetweenObjects, mapPos.z);
                IEnumerator coroutine = MoveTo(pieceToMove, targetPos, 2f);
                StartCoroutine(coroutine);
                currentBottomObjectYpos = pieceToMove.transform.position.y + distanceBetweenObjects;
                currentTopObjectYpos    = targetPos.y;
                tunnelPieces.Enqueue(pieceToMove);
            }
        }
    }
예제 #2
0
    //void HandleMoveTunnelDown() {

    //    // Note: isReversing is currently NOT in use, but the intention is to automatically handle tunnel movement upwards too
    //    if (!isGoingDown) {
    //        targetX += Time.deltaTime;
    //        targetz += Time.deltaTime;
    //    }
    //    else {
    //        targetX -= Time.deltaTime;
    //        targetz -= Time.deltaTime;
    //    }
    //    if (targetX > minmaxX || targetX < -minmaxX) isGoingDown = !isGoingDown;


    //    if (currentTopObjectYpos > this.transform.position.y) {
    //        // if (!isGoingDown) ReverseQueue();



    //        PhylloTunnelPiece pieceToMove = tunnelPieces.Dequeue();
    //        pieceToMove.targetYPos = currentTopObjectYpos - (distanceBetweenObjects * (numberOfObjects - 1));
    //        currentBottomObjectYpos = pieceToMove.targetYPos;
    //        currentTopObjectYpos -= distanceBetweenObjects;
    //        tunnelPieces.Enqueue(pieceToMove);

    //    }

    //}

    // Automatically handles the movement of tunnel pieces in the Y axis. Intended to be called in the Update metho
    void HandleTunnelMove()
    {
        //Vector3 mapPos = MapSpawner.Instance.GetCurrentMapHolder().transform.position;
        Vector3 ownerPos = this.transform.position;


        Vector3 targetPos;


        if (isGoingDown) // Going Down
        {
            if (currentTopObjectYpos < ownerPos.y /*- distanceBetweenObjects*/)
            {
                /*tunnelPieces = */
                ReverseQueueUtil <PhylloTunnelPiece> .ReverseQueue(ref tunnelPieces);

                isGoingDown = !isGoingDown;
                return;
            }

            if (currentTopObjectYpos > ownerPos.y)
            {
                //PhylloTunnelPiece pieceToMove = tunnelPieces.Dequeue();
                //pieceToMove.targetYPos = currentTopObjectYpos - (distanceBetweenObjects * (numberOfObjects - 1));
                //currentBottomObjectYpos = pieceToMove.targetYPos;
                //currentTopObjectYpos -= distanceBetweenObjects;
                //tunnelPieces.Enqueue(pieceToMove);

                targetPos = new Vector3(ownerPos.x, currentTopObjectYpos - (distanceBetweenObjects * (numberOfObjects - 1)), ownerPos.z);
                PhylloTunnelPiece pieceToMove = tunnelPieces.Dequeue();
                pieceToMove.targetYPos  = targetPos.y;
                currentBottomObjectYpos = targetPos.y;
                currentTopObjectYpos   -= distanceBetweenObjects;
                tunnelPieces.Enqueue(pieceToMove);
            }
        }
        else // Going Up
        {
            if (currentTopObjectYpos > ownerPos.y + distanceBetweenObjects)
            {
                /*tunnelPieces = */
                ReverseQueueUtil <PhylloTunnelPiece> .ReverseQueue(ref tunnelPieces);

                isGoingDown = !isGoingDown;
                return;
            }

            if (currentTopObjectYpos < ownerPos.y - distanceBetweenObjects)
            {
                //PhylloTunnelPiece pieceToMove = tunnelPieces.Dequeue();
                //pieceToMove.targetYPos = currentTopObjectYpos - (distanceBetweenObjects * (numberOfObjects - 1));
                //currentBottomObjectYpos = pieceToMove.targetYPos;
                //currentTopObjectYpos -= distanceBetweenObjects;
                //tunnelPieces.Enqueue(pieceToMove);

                targetPos = new Vector3(ownerPos.x, currentTopObjectYpos + distanceBetweenObjects, ownerPos.z);
                PhylloTunnelPiece pieceToMove = tunnelPieces.Dequeue();
                pieceToMove.targetYPos  = targetPos.y;
                currentBottomObjectYpos = pieceToMove.transform.position.y + distanceBetweenObjects;
                currentTopObjectYpos    = targetPos.y;
                tunnelPieces.Enqueue(pieceToMove);
            }
        }
    }