private void Update() { switch (state) { case State.Normal: float moveX = 0f; float moveY = 0f; if (Input.GetKey(KeyCode.W)) { moveY = +1f; } if (Input.GetKey(KeyCode.S)) { moveY = -1f; } if (Input.GetKey(KeyCode.A)) { moveX = -1f; } if (Input.GetKey(KeyCode.D)) { moveX = +1f; } moveDir = new Vector3(moveX, moveY).normalized; if (moveX != 0 || moveY != 0) { // Not idle lastMoveDir = moveDir; } characterBase.PlayMoveAnim(moveDir); if (Input.GetKeyDown(KeyCode.F)) { isDashButtonDown = true; } if (Input.GetKeyDown(KeyCode.Space)) { rollDir = lastMoveDir; rollSpeed = 250f; state = State.Rolling; characterBase.PlayRollAnimation(rollDir); } break; case State.Rolling: float rollSpeedDropMultiplier = 5f; rollSpeed -= rollSpeed * rollSpeedDropMultiplier * Time.deltaTime; float rollSpeedMinimum = 50f; if (rollSpeed < rollSpeedMinimum) { state = State.Normal; } break; } }
private void Update() { switch (state) { case State.Normal: float moveX = 0f; float moveZ = 0f; if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { moveZ = +1f; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { moveZ = -1f; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { moveX = -1f; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { moveX = +1f; } moveDir = new Vector3(moveX, 0f, moveZ).normalized; if (moveX != 0 || moveZ != 0) { // Not idle lastMoveDir = moveDir; } //Vector2 moveDirVector2 = new Vector2(moveDir.x, moveDir.z); characterBase.PlayMoveAnim(moveDir); if (Input.GetKeyDown(KeyCode.F)) { isDashButtonDown = true; } if (Input.GetKeyDown(KeyCode.Space)) { rollDir = lastMoveDir; rollSpeed = 40f; state = State.Rolling; characterBase.PlayRollAnimation(rollDir); } break; case State.Rolling: float rollSpeedDropMultiplier = 5f; rollSpeed -= rollSpeed * rollSpeedDropMultiplier * Time.deltaTime; float rollSpeedMinimum = MOVE_SPEED; if (rollSpeed < rollSpeedMinimum) { state = State.Normal; } break; case State.Busy: break; } }