void move() { float horizontalInput = CrossPlatformInputManager.GetAxis("Horizontal"); if (horizontalInput > 0) { playerSprite.flipX = false; } else if (horizontalInput < 0) { playerSprite.flipX = true; } if ((Input.GetKeyDown(KeyCode.Space) || CrossPlatformInputManager.GetButtonDown("B_Button")) && grounded == true) { rigidBody.velocity = new Vector2(rigidBody.velocity.x, jumpForce); grounded = false; resetJump = true; StartCoroutine(ResetJumpRoutine()); playerAnim.Jump(true); } rigidBody.velocity = new Vector2(horizontalInput * speed, rigidBody.velocity.y); playerAnim.Move(horizontalInput); }
void Update() { float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertical"); if (x != 0f || z != 0f) { playerAnim.Move(); } else { playerAnim.Idle(); } Vector3 moveDirection = new Vector3(x, 0, z); moveDirection = cameraTransform.TransformDirection(moveDirection); moveDirection *= moveSpeed; if (characterController.isGrounded == true) { yVelocity = 0.0f; jumpCount = 0; if (jumped == true) { playerAnim.Grounded(); } jumped = false; } //Debug.Log(characterController.isGrounded); if (Input.GetButtonDown("Jump") && jumpCount < 2) { jumped = true; yVelocity = jumpSpeed; ++jumpCount; playerAnim.Jump(); } yVelocity += (gravity * Time.deltaTime); moveDirection.y = yVelocity; //Debug.Log(yVelocity); characterController.Move(moveDirection * Time.deltaTime); }