private bool ClimbUpChecking() { if (climbDownChecker) { if (upInteractFloor) { if (upInteractFloor.GetLeftSideInteract() && currentFacing) { var distanceX = Mathf.Abs(upInteractFloor.GetLeftSideEdge().x) - transform.position.x; if (distanceX > -0.5f && distanceX < 0.5f) { isCheckingFall = false; canHang = true; lastPosition = new Vector3(upInteractFloor.GetLeftSideEdge().x - 0.3f, transform.position.y, transform.position.z); nextPosition = new Vector3(upInteractFloor.GetLeftSideEdge().x + 0.3f, upInteractFloor.GetLeftSideEdge().y + 0.69f, transform.position.z); transform.position = new Vector3(upInteractFloor.GetLeftSideEdge().x, transform.position.y, transform.position.z); hangPosition = new Vector3(upInteractFloor.GetLeftSideEdge().x - 0.3f, upInteractFloor.GetLeftSideEdge().y - 1, transform.position.z); princeAnimator.SetBool("isJump", true); isMoving = false; climbDownChecker = false; return(true); } else { return(false); } } if (upInteractFloor.GetRightSideInteract() && !currentFacing) { var distanceX = Mathf.Abs(upInteractFloor.GetRightSideEdge().x) - transform.position.x; if (distanceX > -0.5f && distanceX < 0.5f) { canHang = true; isCheckingFall = false; lastPosition = new Vector3(upInteractFloor.GetRightSideEdge().x + 0.3f, transform.position.y, transform.position.z); nextPosition = new Vector3(upInteractFloor.GetRightSideEdge().x - 0.3f, upInteractFloor.GetRightSideEdge().y + 0.69f, transform.position.z); transform.position = new Vector3(upInteractFloor.GetRightSideEdge().x, transform.position.y, transform.position.z); hangPosition = new Vector3(upInteractFloor.GetRightSideEdge().x + 0.3f, upInteractFloor.GetRightSideEdge().y - 1, transform.position.z); princeAnimator.SetBool("isJump", true); isMoving = false; climbDownChecker = false; return(true); } else { return(false); } } } } return(false); }
protected override void OnNormal() { if (controlable) { #region InteractKey Implement if (InputManager.GetKeyDown_Interact() && GameCore.combatController.canCombat && isHaveSword) { StartCoroutine(IdleToCombat()); } else if (InputManager.GetKeyDown_Interact()) { if (interactObject) { if (interactObject.CompareTag("PotionSmall")) { transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, transform.position.z); Destroy(interactObject); princeAnimator.SetTrigger("Heal"); StartCoroutine(potionSmallPlay()); } else if (interactObject.CompareTag("PotionLarge")) { transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, transform.position.z); Destroy(interactObject); princeAnimator.SetTrigger("Heal"); StartCoroutine(potionLargePlay()); } else if (interactObject.CompareTag("Sword")) { transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, transform.position.z); isHaveSword = true; Destroy(interactObject); princeAnimator.SetTrigger("GetSword"); princeSoundHandler.swordGetPlay(); } } } else if (!InputManager.GetKey_Interact()) { if (isHang && !InputManager.GetKey_Up()) { princeAnimator.SetBool("isHang", false); characterRigid.simulated = true; isCheckingFall = true; isHang = false; isFromHang = true; transform.position = new Vector3(lastPosition.x, transform.position.y, transform.position.z); } else if (isHang && InputManager.GetKey_Up()) { princeAnimator.SetTrigger("ClimbUp"); controlable = false; } } #endregion #region Keydown Implements if (InputManager.GetKey_Down()) { if (!isCrouch) { if (ClimbDownChecking()) { } else { if (!isCrouch) { isCrouch = true; predictPosition = transform.position; } princeAnimator.SetBool("Crouch", true); } } } else if (!InputManager.GetKey_Down()) { if (isCrouch) { isCrouch = false; princeAnimator.SetBool("Crouch", false); } } #endregion #region KeyUp Implement if (InputManager.GetKey_Up() && !isHang) { if (!ClimbUpChecking() && currentAnimationClip == "Idle") { princeAnimator.SetBool("isJump", true); canInteruptJump = true; } } else if (!InputManager.GetKey_Up()) { } if (InputManager.GetKeyDown_Up()) { } #endregion #region KeyLeft Implement if (InputManager.GetKeyDown_Left()) { if (isCrouch) { if (!currentFacing) { princeAnimator.SetTrigger("CrouchStep"); stepBlockCount = 0; } } else { if (!currentFacing && InputManager.GetKey_Interact()) { var movingIncreast = (currentFacing) ? normalStepScale : -normalStepScale; predictPosition = new Vector3(transform.position.x + movingIncreast, transform.position.y, transform.position.z); if (downInteractFloor && stepBlockCount < 2) { if (downInteractFloor.GetLeftSideInteract()) { var edgePosition = downInteractFloor.GetLeftSideEdge().x + 0.3f; var distance = Mathf.Abs(predictPosition.x) - edgePosition; var distanceCurrent = Mathf.Abs(transform.position.x) - edgePosition; if (predictPosition.x < downInteractFloor.GetLeftSideEdge().x + 0.3f) { if (distanceCurrent == 0) { predictPosition = transform.position; isStepBlock = true; princeAnimator.SetTrigger("Step"); stepBlockCount++; } else { predictPosition = new Vector3(downInteractFloor.GetLeftSideEdge().x + 0.3f, transform.position.y, transform.position.z); princeAnimator.SetTrigger("Step"); } isInAction = true; } else { princeAnimator.SetTrigger("Step"); isInAction = true; } } else { princeAnimator.SetTrigger("Step"); isInAction = true; } } else { princeAnimator.SetTrigger("Step"); isInAction = true; } } else if (currentFacing) { if (isTurning) { princeAnimator.SetTrigger("Turn"); isInAction = true; } } } } if (InputManager.GetKey_Left() && !isCrouch && !isInAction) { if (canInteruptJump && InputManager.GetKey_Up() && !currentFacing && currentAnimationClip == "jump") { princeAnimator.SetTrigger("IdleJump"); princeAnimator.SetBool("isJump", false); controlable = false; canInteruptJump = false; } else if (isRunning && InputManager.GetKey_Up() && !currentFacing) { princeAnimator.SetTrigger("RunJump"); controlable = false; isRunJump = true; } else if (isRunning) { var movingIncreast = (currentFacing) ? runSpeed : -runSpeed; /* characterRigid.velocity = new Vector2(movingIncreast, characterRigid.velocity.y); */ transform.Translate(new Vector3(movingIncreast * Time.deltaTime, 0, 0)); isMoving = false; } else { if (!currentFacing) { princeAnimator.SetBool("Running", true); stepBlockCount = 0; } else if (currentFacing) { princeAnimator.SetTrigger("Turn"); isInAction = true; } } } else if (!InputManager.GetKey_Left() && isRunning && !currentFacing) { if (InputManager.GetKey_Right()) { isMoving = true; isTurning = true; settingMoveSpeed = runStopSpeed - 0.6f; characterRigid.simulated = false; isCheckingFall = false; princeAnimator.SetBool("RunTurn", true); characterRigid.velocity = Vector2.zero; var movingIncreast = (currentFacing) ? runStopScale + 0.3f : -(runStopScale + 0.3f); predictPosition = new Vector3(transform.position.x + movingIncreast, transform.position.y, transform.position.z); } else if (runStartCounter <= Time.time) { isRunning = false; isMoving = true; settingMoveSpeed = runStopSpeed; characterRigid.velocity = Vector2.zero; princeAnimator.SetBool("Running", false); princeAnimator.SetBool("ForwardBlock", forwardBlock); var movingIncreast = (currentFacing) ? runStopScale : -runStopScale; predictPosition = new Vector3(transform.position.x + movingIncreast, transform.position.y, transform.position.z); } else { var movingIncreast = (currentFacing) ? runSpeed : -runSpeed; characterRigid.velocity = new Vector2(movingIncreast, characterRigid.velocity.y); runStartCounter = Time.time; } } #endregion #region KeyRight Implement if (InputManager.GetKeyDown_Right()) { if (isCrouch) { if (currentFacing) { princeAnimator.SetTrigger("CrouchStep"); stepBlockCount = 0; } } else { if (currentFacing && InputManager.GetKey_Interact()) { var movingIncreast = (currentFacing) ? normalStepScale : -normalStepScale; predictPosition = new Vector3(transform.position.x + movingIncreast, transform.position.y, transform.position.z); if (downInteractFloor && stepBlockCount < 2) { if (downInteractFloor.GetRightSideInteract()) { var edgePosition = downInteractFloor.GetRightSideEdge().x - 0.3f; var distance = Mathf.Abs(predictPosition.x) - edgePosition; var distanceCurrent = Mathf.Abs(transform.position.x) - edgePosition; if (predictPosition.x > downInteractFloor.GetRightSideEdge().x - 0.3f) { if (distanceCurrent == 0) { predictPosition = transform.position; isStepBlock = true; princeAnimator.SetTrigger("Step"); stepBlockCount++; } else { predictPosition = new Vector3(downInteractFloor.GetRightSideEdge().x - 0.3f, transform.position.y, transform.position.z); princeAnimator.SetTrigger("Step"); } isInAction = true; } else { princeAnimator.SetTrigger("Step"); isInAction = true; } } else { princeAnimator.SetTrigger("Step"); isInAction = true; } } else { princeAnimator.SetTrigger("Step"); isInAction = true; } } else if (!currentFacing) { princeAnimator.SetTrigger("Turn"); isInAction = true; } } } if (InputManager.GetKey_Right() && !isCrouch && !isInAction) { if (canInteruptJump && InputManager.GetKey_Up() && currentFacing && currentAnimationClip == "jump") { princeAnimator.SetTrigger("IdleJump"); princeAnimator.SetBool("isJump", false); controlable = false; canInteruptJump = false; } else if (isRunning && InputManager.GetKey_Up() && currentFacing) { princeAnimator.SetTrigger("RunJump"); controlable = false; isRunJump = true; } else if (isRunning) { var movingIncreast = (currentFacing) ? runSpeed : -runSpeed; /* characterRigid.velocity = new Vector2(movingIncreast, characterRigid.velocity.y); */ transform.Translate(new Vector3(movingIncreast * Time.deltaTime, 0, 0)); isMoving = false; } else { if (currentFacing) { princeAnimator.SetBool("Running", true); stepBlockCount = 0; } else if (!currentFacing) { princeAnimator.SetTrigger("Turn"); isInAction = true; } } } else if (!InputManager.GetKey_Right() && isRunning && currentFacing) { if (InputManager.GetKey_Left()) { isMoving = true; isTurning = true; settingMoveSpeed = runStopSpeed - 0.6f; characterRigid.simulated = false; isCheckingFall = false; princeAnimator.SetBool("RunTurn", true); characterRigid.velocity = Vector2.zero; var movingIncreast = (currentFacing) ? runStopScale + 0.3f : -(runStopScale + 0.3f); predictPosition = new Vector3(transform.position.x + movingIncreast, transform.position.y, transform.position.z); } if (!isTurning) { if (runStartCounter <= Time.time) { isRunning = false; isMoving = true; settingMoveSpeed = runStopSpeed; princeAnimator.SetBool("Running", false); princeAnimator.SetBool("ForwardBlock", forwardBlock); characterRigid.velocity = Vector2.zero; var movingIncreast = (currentFacing) ? runStopScale : -runStopScale; predictPosition = new Vector3(transform.position.x + movingIncreast, transform.position.y, transform.position.z); } else { var movingIncreast = (currentFacing) ? runSpeed : -runSpeed; characterRigid.velocity = new Vector2(movingIncreast, characterRigid.velocity.y); runStartCounter = Time.time; } } } #endregion } }