3D Sidescroller jumping one time

I am new to unity programming, but I know C# and I would like a way to make a 3D character jump.

I have this code for jumping:

if (Input.GetKey("space"))
        {
            rb.AddForce(0, jumpforce * Time.deltaTime, 0, ForceMode.VelocityChange);
        }

The problem is that the character can hold down space to fly, whereas I want it to just jump one time.

How could I do this?

You need to check if you’re on the ground before jumping.

How to do that can vary.

For example you can do a raycast downward to test if there is a ground surface right under the player. Or if you’re using a CharacterController there is an ‘isGrounded’ flag that is set true if the last call to ‘Move’ pushed it into a surface beneath itself. Or with a Rigidbody you can listen to collision events and use some logic to decide if you’re on the ground (checking direction and if the struck collider is ground). Or any number of different methods that you would select based on your desired gameplay feel.

Thanks for the reply, I tried this:

void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.collider.tag == "Platform")
        {
            allowjump = true;
        }
    }
if (Input.GetKey("space"))
        {
            if (allowjump == true)
            {
                allowjump = false;
                jump();
            }
        }

But the character is unable to jump at all. I think it is just a logic thing I cannot see myself. Do you see anything wrong with these statements?