How do i make a jump function in Unity 2D (C#)

Hello.
I want to add a jump function, but whatever i do, it won’t work.
I’ve tried this:

 if (Input.GetKey(KeyCode.Space))
            {
                rb.AddForce(Vector2.up * JumpForce, 0);
            }

But it doesn’t work…
I don’t get any errors, but when i press Space, nothing happens…

hi try this.

    public float moveSpeed;
public float jumpHeight;
public Rigidbody2D rig;

       void Start () {
	 
	rig = GetComponent<Rigidbody2D> ();

      }

      void Update(){

       if (Input.GetKeyDown(KeyCode.Space)){
        rig.velocity = new Vector2 (rig.velocity.x,jumpHeight);

     }

   }