protected virtual void Attack() // 몬스터 공격 { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk")) { if ((RecognitionX <= AttackRange && RecognitionX > -AttackRange) && (RecognitionY <= JumpRange && RecognitionY > -JumpRange) && !Jumping) // 방향 오른쪽일때 공격 { MyAnimator.SetTrigger("Attack"); } } }
private void Flip(float horizontal) { if (!MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide")) { if ((horizontal > 0 && !facingRight) || (horizontal < 0 && facingRight)) { ChangeDirection(); } } }
protected override void Trace() { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk") && transform.localScale.x > 0 && Player.transform.position.x < transform.position.x) // 오른쪽일 때 방향전환 { ChangeDirection(); } if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk") && transform.localScale.x < 0 && Player.transform.position.x > transform.position.x) // 왼쪽일 때 방향전환 { ChangeDirection(); } }
void FixedUpdate() { float horizontal = Input.GetAxis("Horizontal"); OnGround = IsGrounded() && !MyAnimator.GetCurrentAnimatorStateInfo(1).IsTag("JumpUp"); HandleMovement(horizontal); Flip(horizontal); //HandleAttacks (); HandleLayers(); //ResetValue (); }
private void HandleMovement(float horizontal) { if (!MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("PlayerJump") && (grounded || AirControl)) { myRigidbody.velocity = new Vector2(horizontal * movementSpeed * Time.deltaTime, myRigidbody.velocity.y); } if (grounded && Jumping) { SoundManagerScript.PlaySound("PlayerJump"); grounded = false; myRigidbody.AddForce(new Vector2(0, jumpForce) * Time.deltaTime); MyAnimator.SetTrigger("Jump"); myRigidbody.velocity = Vector2.zero; } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
void FixedUpdate() { float horizontal = Input.GetAxis("Horizontal"); OnGround = IsGrounded() && !MyAnimator.GetCurrentAnimatorStateInfo(1).IsTag("JumpUp"); HandleMovement(horizontal); Flip(horizontal); //HandleAttacks (); HandleLayers(); //ResetValue (); if (IsDead) { MyAnimator.SetLayerWeight(1, 0); MyAnimator.SetTrigger("die"); Freeze = true; } }
protected virtual void Trace() // 플레이어 따라서 방향 전환을 하는 조건 { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk") && transform.localScale.x > 0 && Player.transform.position.x < transform.position.x) // 오른쪽일 때 방향전환 { if ((RecognitionY < 1 && RecognitionY > -3.7f)) // 플레이어가 Y축이 더 높거나 동일할때만 { ChangeDirection(); } } if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk") && transform.localScale.x < 0 && Player.transform.position.x > transform.position.x) // 왼쪽일 때 방향전환 { if ((RecognitionY < 1 && RecognitionY > -3.7f)) // 플레이어가 Y축이 더 높거나 동일할때만 { ChangeDirection(); } } }
protected virtual void Move() // 몬스터 이동 { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk")) // 이동 { if (transform.localScale.x >= 1) // 오른쪽 보고있을때 { transform.Translate(transform.right * MonsterSpeed * Time.deltaTime, Space.World); } else // 왼쪽 보고있을때 { transform.Translate(-transform.right * MonsterSpeed * Time.deltaTime, Space.World); } } if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("NoMove")) { transform.Translate(Vector2.zero, Space.World); } }
private void FixedUpdate() { if (DataController.instance.gameData.CharacterNum == 1 && !DataController.instance.gameData.Damaged && !DataController.instance.gameData.Dead) // 움직이고 점프하는 조건 { if (DataController.instance.gameData.P1Skill2 < 5) { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk")) /*(!Attack1 && !Attack2) && (!Skill1 && !Skill2 && !Skill3)*/ { Move(DataController.instance.gameData.P1_MoveSpeed); } } else { if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk") || MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Skill2")) /*(!Attack1 && !Attack2) && (!Skill1 && !Skill2 && !Skill3)*/ { Move(DataController.instance.gameData.P1_MoveSpeed); } } } MyRigidbody.velocity = new Vector2(MyRigidbody.velocity.x, PlayerRigidbody.MyRigidbody.velocity.y); //Debug.Log(MyRigidbody.velocity); }
protected void Jump(float JumpSpeed) { if (MyRigidbody.velocity.y != 0) { MyAnimator.SetBool("Jump", true); Jumping = true; } if (MyRigidbody.velocity.y < 0) { MyBoxCollider.enabled = true; } if ((RecognitionX >= -AttackRange && RecognitionX <= AttackRange) && RecognitionY <= -JumpRange && MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk")) { if ((transform.position.x >= JumpLimit[0] && transform.position.x <= JumpLimit[1]) || (transform.position.x >= JumpLimit[2] && transform.position.x <= JumpLimit[3])) { Jumping = true; MyRigidbody.velocity = Vector2.zero; Vector2 JumpVelocity = new Vector2(JumpSpeed, JumpForce); MyRigidbody.AddForce(JumpVelocity, ForceMode2D.Impulse); } } }
private void HandleInput() { if (Input.GetKeyDown(KeyCode.L) && mana.CurrentValue > 0) { mana.CurrentValue -= 20; GameManager.Instance.NumberKunai += 2; } if (Input.GetKeyDown(KeyCode.J) && !OnLadder && !staminaEmpty) { castingBar.GetComponent <CastingBar>().StopCasting(); MyAnimator.SetTrigger("attack"); stamina.CurrentValue -= 20; } if (Input.GetKeyDown(KeyCode.LeftControl) && !MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Idle") && !OnLadder) { MyAnimator.SetTrigger("slide"); stamina.CurrentValue -= 15; } if (Input.GetKeyDown(KeyCode.Space) && !OnLadder) { castingBar.GetComponent <CastingBar>().StopCasting(); MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.K) && !OnLadder && GameManager.Instance.NumberKunai > 0) { castingBar.GetComponent <CastingBar>().StopCasting(); MyAnimator.SetTrigger("throw"); stamina.CurrentValue -= 10; } if (Input.GetKeyDown(KeyCode.F)) { castingBar.GetComponent <CastingBar>().StopCasting(); Interact(); } if (Input.GetKeyDown(KeyCode.UpArrow)) { if (upIndex >= upItem.childCount - 1) { upIndex = 0; } else { upIndex++; } } if (Input.GetKeyDown(KeyCode.DownArrow)) { if (downIndex >= downItem.childCount - 1) { downIndex = 0; } else { downIndex++; } } //if (Input.GetKeyDown(KeyCode.LeftArrow)) //{ // if (leftIndex >= leftItem.childCount - 1) // { // leftIndex = 0; // } // else // { // leftIndex++; // } //} //if (Input.GetKeyDown(KeyCode.RightArrow)) //{ // if (rightIndex >= rightItem.childCount - 1) // { // rightIndex = 0; // } // else // { // rightIndex++; // } //} }