예제 #1
0
        private void ClimbLadder_SuperUpdate()
        {
            Vector3 moveInput = rpgCharacterController.moveInput;

            // If no input, don't do anything.
            if (moveInput == Vector3.zero)
            {
                return;
            }

            // If we can't move (i.e. because we're animating) ignore input.
            if (!rpgCharacterController.canMove)
            {
                return;
            }

            float ladderThreshold = 1.2f;

            if (moveInput.y > 0f)
            {
                Collider ladder    = rpgCharacterController.ladder;
                Vector3  ladderTop = new Vector3(transform.position.x, ladder.bounds.max.y - ladderThreshold, transform.position.z);

                // Climb Off Top or Climb Up.
                if (superCharacterController.PointBelowHead(ladderTop))
                {
                    rpgCharacterController.ClimbLadder(3);
                    rpgCharacterController.OnUnlockMovement += IdleOnceAfterMoveUnlock;
                }
                else
                {
                    rpgCharacterController.ClimbLadder(1);
                }
            }
            else if (moveInput.y < 0f)
            {
                Collider ladder       = rpgCharacterController.ladder;
                Vector3  ladderBottom = new Vector3(transform.position.x, ladder.bounds.min.y + ladderThreshold, transform.position.z);

                // Climb Off Bottom or Climb Down.
                if (superCharacterController.PointAboveFeet(ladderBottom))
                {
                    rpgCharacterController.ClimbLadder(4);
                    rpgCharacterController.OnUnlockMovement += IdleOnceAfterMoveUnlock;
                }
                else
                {
                    rpgCharacterController.ClimbLadder(2);
                }
            }
        }