jumping script boolean help (2D)

var canJump : Boolean = true;

// i had more code but this is all you need

function OnCollisionEnter2D(other : Collision2D){


if(Input.GetKeyDown("space") && canJump){
this.rigidbody2D.velocity.y += 5; //jump
canJump = false; //Disable jumping until landing
}

if(other.transform.tag == "Ground"){ 
    canJump = true; 
} }

what is wrong with this, its set to can jump (I can check in unity) but I can’t actually jump. It wont bring my character to jump? Help??

Try using OnCollisionStay2D instead, and check if “space” input is assigned properly.

Yeah I solved this

this.rigidbody2D.velocity.y += 5; //jump

that was what was the problem. The +=. I simply changed it to = and it was solved. I spent 6 hours trying to redo the code to jump and it was that easy -_-