public void Update() { _stateInfo = _player.anim.GetCurrentAnimatorStateInfo(0); AttackRayCast(); if (_stateInfo.IsName("Jump") && _player.anim.GetInteger("state") == 2) { _player.SetState(new PlayerIdleState(_player)); _player.anim.SetInteger("state", 0); } if (Input.GetKeyDown(KeyCode.X)) { HandleAttack(_stateInfo); } if (Input.GetKeyDown(KeyCode.C)) { _player.SetState(new PlayerJumpState(_player)); _player.anim.SetInteger("state", 1); } if (_stateInfo.IsName("Attack1") || _stateInfo.IsName("Attack2") || _stateInfo.IsName("Attack3")) { if (_stateInfo.normalizedTime > 1.0f) { _player.anim.SetInteger("state", 0); _player.SetState(new PlayerIdleState(_player)); return; } } }
public void Update() { if (HandleKey(_player._inputQueue.GetIndex()) != -1) { return; } if (Input.GetKeyDown(KeyCode.C)) { _player.SetState(new PlayerJumpState(_player)); _player.anim.SetInteger("state", 1); } if (Input.GetKeyDown(KeyCode.X)) { _player.SetState(new PlayerAttackState(_player)); _player.anim.SetInteger("state", 2); } if (isClimb == true && Input.GetKeyDown(KeyCode.UpArrow) && hit.collider != null) { if (_player.trs.parent == null) { _player.trs.parent = hit.collider.transform; _player.trs.localPosition = new Vector3(-0.372f, _player.trs.localPosition.y, _player.trs.localPosition.z); } _player.SetState(new PlayerClimbState(_player)); _player.anim.SetInteger("state", 3); } if (isClimb == true && Input.GetKeyDown(KeyCode.DownArrow) && hitDown.collider != null) { if (_player.trs.parent == null) { _player.trs.parent = hitDown.collider.transform; _player.rig.velocity = new Vector2(0, 0); _player.trs.localPosition = new Vector3(-0.372f, 2.32f, _player.trs.localPosition.z); } _player.SetState(new PlayerClimbState(_player)); _player.anim.SetInteger("state", 3); } horizontal = Input.GetAxis("Horizontal"); if (horizontal != 0) { _player.anim.SetFloat("Speed", horizontal > 0 ? 1 : -1); } speedX = horizontal * 5.0f; _player.anim.SetFloat("Direction", horizontal); _player.rig.velocity = new Vector2(speedX, _player.rig.velocity.y); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.tag.CompareTo("path") == 0) { if (anim.GetCurrentAnimatorStateInfo(0).IsName("Jump")) { AudioManager.Instance.PlaySound(6); } _player.SetState(new PlayerIdleState(_player)); anim.SetInteger("state", 0); anim.SetFloat("JumpDirection", 0); anim.SetInteger("JumpAt", 0); rig.velocity = new Vector2(0, 0); rig.gravityScale = 2.5f; } }
public void Update() { _stateInfo = _player.anim.GetCurrentAnimatorStateInfo(0); if (_stateInfo.IsName("Skill") && _stateInfo.normalizedTime > 1.0f) { _player.anim.SetInteger("state", 0); _player.SetState(new PlayerIdleState(_player)); return; } ChooseSkill(index); }
public void Update() { horizontal = Input.GetAxis("Horizontal"); if (horizontal != 0) { _player.anim.SetFloat("Speed", horizontal > 0 ? 1 : -1); } if (horizontal != 0 && Input.GetKeyDown(KeyCode.C)) { _player.anim.speed = 1; _player.SetState(new PlayerJumpState(_player)); _player.anim.SetInteger("state", 1); } if (_player.trs.localPosition.x != 0.372f) { _player.trs.localPosition = new Vector3(-0.372f, _player.trs.localPosition.y, _player.trs.localPosition.z); } if (Input.GetKeyUp(KeyCode.UpArrow) && !Input.GetKey(KeyCode.DownArrow)) { _player.rig.velocity = new Vector2(0, 0); _player.anim.speed = 0; } if (Input.GetKeyUp(KeyCode.DownArrow) && !Input.GetKey(KeyCode.UpArrow)) { _player.anim.speed = 0; } if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow)) { if (_player.anim.speed != 1) { _player.anim.speed = 1; } } vertical = Input.GetAxis("Vertical"); if (vertical != 0) { _player.rig.velocity = new Vector2(0, vertical * 1.5f); } }