コード例 #1
0
 // Function to perform the wall jump. Resets several variables and performs a jump.
 void PerformWallJump()
 {
     stuckToWall = false;
     wallRunning = false;
     wallSliding = false;
     Unstick();
     isWallJumping = true;
     if (wallJump.allowDoubleJump)
     {
         player.ResetJumps();
     }
     else
     {
         player.SetJumps(1);
     }
     player.Jump();
 }
コード例 #2
0
        // Update is called once per frame.
        void Update()
        {
            // Check if the player's hitbox collides with a ladder.
            Vector2 pos    = transform.position;
            Vector2 pointA = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2), pos.y + boxCollider.offset.y - (boxCollider.size.y / 2));
            Vector2 pointB = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));

            hitLadder = Physics2D.OverlapArea(pointA, pointB, ladderLayer);

            // If the player isn't currently on a ladder, there is a ladder collission and the player isn't falling, dashing, crouching, sliding or stuck on a wall...
            if (!player.onLadder && hitLadder && !player.falling && !player.dashing && !player.crouching && !player.sliding && !player.stuckToWall)
            {
                // ... cache the vertical input.
                float v = Input.GetAxis("Vertical");

                // If the player isn't on a ladder and the vertical movement is either moving up or down...
                if (!player.onLadder && (v > 0.1 || v < -0.1))
                {
                    // ... make sure the player is stuck to the ladder.
                    Stick();
                }
            }

            // If there isn't a collission with a ladder and the player is considered on a ladder...
            if (!hitLadder && player.onLadder)
            {
                // ... make the player unstuck from the ladder.
                Unstick();
            }

            // If the player is on a ladder, there is a ladder object and the player is allowed to jump...
            if (player.onLadder && ladder && ladder.allowJump && Input.GetButtonDown("Jump"))
            {
                // ... unstick the player from the ladder and perform the jump.
                Unstick();
                player.Jump();
            }
        }