Why my character going up automatically though I'm not pressing any button? I want to control my player jump movement. But I cant do it. What is the solution? Please explain. Can you also suggest how can I customise my jump, like jump twice? etc
public class movement: MonoBehaviour {
public float speed = 10;
private Rigidbody2D rb;
public float jumpSpeed = 1;
void Start() {
rb = GetComponent < Rigidbody2D > ();
}
// Update is called once per frame
void Update() {
Jump();
var inputX = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3(inputX, 0, 0) * speed;
movement *= Time.deltaTime;
transform.Translate(movement);
Vector3 characterScale = transform.localScale;
if (inputX < 0) {
transform.localScale = new Vector3(5, transform.localScale.y, transform.localScale.z);
}
if (inputX > 0) {
transform.localScale = new Vector3(-5, transform.localScale.y, transform.localScale.z);
}
}
void Jump() {
if (Input.GetKeyDown(KeyCode.Space));
rb.velocity = Vector2.up * jumpSpeed;
}
}