コード例 #1
0
    void MovePlayerToStairs(StairController stairController, GameObject triggerStep)
    {
        isMovingToStairs = true;
        isMovingOnStairs = false;
        playerPos        = levelManager.playerController.player.transform.position;
        Vector2 targetPos = triggerStep.GetComponent <Collider2D>().bounds.center;

        if (stairController.GetStairDirection() == StairController.STAIR_DIRECTION.up)
        {
            // a staircase goes up if it moves from left(bottom) to right (top)
            if (triggerStep.transform.position == stairController.leftEndStep.transform.position)
            {
                // this means we're at the left(bottom) end of a staircase that goes up
                targetPos = DeterminePlayerTarget(triggerStep, 0.25f, 0.5f);
            }
            else
            {
                // we must be at the right(top) end of a staircase that goes up
                targetPos = DeterminePlayerTarget(triggerStep, -0.75f, 0.5f);
            }
        }
        else
        {
            // a staircase goes down if it moves from left(top) to right(bottom)
            if (triggerStep.transform.position == stairController.leftEndStep.transform.position)
            {
                // this means we're at the left(top) end of a staircase that goes down
                targetPos = DeterminePlayerTarget(triggerStep, 0.75f, 0.5f);
            }
            else
            {
                // we must be at the right(top) end of a staircase that goes up
                targetPos = DeterminePlayerTarget(triggerStep, -0.25f, 0.5f);
            }
        }

        FlipOnStairs(targetPos.x);

        player.GetComponent <PhysicsObject>().enabled = false;
        runAfterMoving = RunAfterMovingToStairs;
        StartCoroutine(MovePlayer(targetPos, transitionSpeed));
    }
コード例 #2
0
    void MovePlayerOffStairs(int directionToMove)
    {
        isMovingOffStairs = true;
        levelManager.playerController.SetStairState(PlayerController.STAIR_STATE.off_stair);
        Vector2 targetPos = Vector2.zero;

        playerPos = levelManager.playerController.player.transform.position;
        if (directionToMove == 1)
        {
            targetPos.x = playerPos.x + 2f;
        }
        else
        {
            targetPos.x = playerPos.x + -2f;
        }
        targetPos.y    = playerPos.y;
        runAfterMoving = RunAfterMovingOffStairs;
        levelManager.playerController.playerAnimator.SetBool("onStair", false);
        levelManager.playerController.playerAnimator.SetFloat("velocityX", 1);
        StartCoroutine(MovePlayer(targetPos, transitionSpeed));
    }
コード例 #3
0
    void MoveOnStairs(int directionToMove, StairController.STAIR_DIRECTION stairDirection)
    {
        isMovingOnStairs = true;
        playerPos        = levelManager.playerController.player.transform.position;
        Vector2 targetPos = Vector2.zero;

        //target.x is the same regardless of stairDirection
        targetPos.x = playerPos.x + MoveXOnStairs(directionToMove);

        //target.y is determined by move direction and stair direction
        //target.y is the same as stair direction on right and inverted on left
        targetPos.y = playerPos.y + moveYOnStairs(directionToMove, stairDirection);

        FlipOnStairs(targetPos.x);

        if ((!isMovingToStairs || !isMovingOffStairs) && CheckBound(targetPos.x, directionToMove, stairDirection) == 0)
        {
            runAfterMoving = RunAfterMovingOnStairs;
            if (stairController.GetStairDirection() == StairController.STAIR_DIRECTION.up)
            {
                levelManager.playerController.playerAnimator.SetInteger("stairDirection", directionToMove);
            }
            else
            {
                levelManager.playerController.playerAnimator.SetInteger("stairDirection", -directionToMove);
            }
            StartCoroutine(MovePlayer(targetPos, climbSpeed));
        }
        else if (CheckBound(targetPos.x, directionToMove, stairDirection) != 0)
        {
            MovePlayerOffStairs(directionToMove);
        }
        else
        {
            levelManager.playerController.playerAnimator.SetInteger("stairDirection", 0);
            isMovingOnStairs = false;
        }
    }