- Home /
Question by
sigurolio · Jan 23, 2013 at 01:42 PM ·
2dinputcharactercontrollerjump
Don't jump continuously when button held down
I use this function to control my character controller component:
void MovementActivity() {
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= walkSpeed;
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
This is gotten from the Unity documentation if i remember right. I wan't to change it so that i have to press jump button again to jump. Im still learning how the Input class works. Any ideas how to do that?
Comment
Input.GetButtonDown
check this link, look at all the options under Class Functions, click on one to see more information.