void Update() { if (!isDeath) { if (isInputJump()) { if (pushPullScript.isPullingObject()) { pushPullScript.releaseObject(); } if (groundScript.GetTouchGround()) { groundScript.Jump(); } //else if (ropeScript.isClimbRope()) { //ropeScript.JumpOff(); //} } if (isInputFire1()) { ping = shadowScript.isActive; if (!shadowScript.isActive) { shadowScript.activate(); } else { shadowScript.deactivate(); //firing(); } } } }
void FixedUpdate() { float verticalSpeed; float horizontalSpeed; verticalSpeed = Input.GetAxis("Vertical"); horizontalSpeed = Input.GetAxis("Horizontal"); if (isClimbingLadder) { playerBody.gravityScale = 0; } else { playerBody.gravityScale = 1; } if (!playerScript.immovable) { if (isClimbingLadder && isLadderSet) { bool isStillOnLadder; isStillOnLadder = true; if (verticalSpeed < 0 && ladder.allowMoveDown) { if (!ladder.allowFallBottom) { isStillOnLadder = updateLadderArea(0, 0, 0, -0.1f); } if ((!ladder.allowFallBottom) && (!isStillOnLadder)) { playerBody.velocity = new Vector2(playerBody.velocity.x, 0); } else { playerBody.velocity = new Vector2(playerBody.velocity.x, verticalSpeed - (climbSpeed)); playerAnimation.SetFloat("climbSpeed", Mathf.Abs(verticalSpeed)); } } else if (verticalSpeed > 0 && ladder.allowMoveUp) { if (!ladder.allowFallTop) { isStillOnLadder = updateLadderArea(0, 0.1f, 0, 0); } if ((!ladder.allowFallTop) && (!isStillOnLadder)) { playerBody.velocity = new Vector2(playerBody.velocity.x, 0); } else { playerBody.velocity = new Vector2(playerBody.velocity.x, verticalSpeed + (climbSpeed)); playerAnimation.SetFloat("climbSpeed", Mathf.Abs(verticalSpeed)); } } else { playerBody.velocity = new Vector2(playerBody.velocity.x, 0); } if (groundScript.GetTouchGround() && (horizontalSpeed < 0 || horizontalSpeed > 0)) { unstickFromLadder(); } else if (ladder.allowSnapToMiddle) { if (isSnappedToMiddle && (verticalSpeed == 0) && ((ladder.allowFallLeft && horizontalSpeed < 0) || (ladder.allowFallRight && horizontalSpeed > 0))) { unstickFromLadder(); } else { if (transform.position.x > (onLadderArea.transform.position.x - 0.05f) && transform.position.x < (onLadderArea.transform.position.x + 0.05f)) { playerBody.velocity = new Vector2(0, playerBody.velocity.y); isSnappedToMiddle = true; } else { Vector2 gotoCenter = (new Vector3(onLadderArea.transform.position.x, transform.position.y) - transform.position).normalized * snapSpeed; playerBody.velocity = new Vector2(gotoCenter.x, playerBody.velocity.y); isSnappedToMiddle = false; } } } else { if (horizontalSpeed < 0 && ladder.allowMoveLeft) { if (!ladder.allowFallLeft) { isStillOnLadder = updateLadderArea(0, 0, -0.1f, 0); } if ((!ladder.allowFallLeft) && (!isStillOnLadder)) { playerBody.velocity = new Vector2(0, playerBody.velocity.y); } else { playerBody.velocity = new Vector2(horizontalSpeed - climbSpeed, playerBody.velocity.y); playerAnimation.SetFloat("climbSpeed", Mathf.Abs(verticalSpeed)); } } else if (horizontalSpeed > 0 && ladder.allowMoveRight) { if (!ladder.allowFallRight) { isStillOnLadder = updateLadderArea(0.1f, 0, 0, 0); } if ((!ladder.allowFallRight) && (!isStillOnLadder)) { playerBody.velocity = new Vector2(0, playerBody.velocity.y); } else { playerBody.velocity = new Vector2(horizontalSpeed + climbSpeed, playerBody.velocity.y); playerAnimation.SetFloat("climbSpeed", Mathf.Abs(verticalSpeed)); } } } } } }