I'm trying to make my player fly up in the air on key press

Here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fly : MonoBehaviour {

// Use this for initialization
void Start () {
	
}

// Update is called once per frame
void Update () {
	if(Input.GetKeyDown("F")){

		Rigidbody.AddForce(transform.up * 100);

	}
}

}

But I get this error:

Assets/Fly.cs(18,14): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)’

You Haven’t Anything To Access The Rigidbody, Even You’re Not Using GetComponent()! Replace:

Rigidbody.AddForce(transform.up * 100);

With:

GetComponent<Rigidbody>().AddForce(transform.up * 100);

And It Should Work.

That is because you are not referencing the RigidBody.

As you can see in the documents here:

You need to first create a variable to store the RigidBody, reference it in the Start() and then call it on Update. You can also find the component inside the Update() but that is really not recommended for performance reasons.

public Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
          if(Input.GetKeyDown("F")){
               rb.AddForce(transform.up * 100);
          }
    }