I’m getting this error-
Assets/Scripts/PlayerMovement.cs(17,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)’
I’m new to making games so please help.This is my code-
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private float maxSpeed;
private Vector3 input;
// Use this for initialization
void Start (){
}
// Update is called once per frame
void Update () {
input = new Vector3(Input.GetAxis ("Horizontal"),Input.GetAxis ("Vertical"));
Rigidbody.AddForce(input * moveSpeed);
}
}
It should be rigidbody.AddForce(input * moveSpeed);
with a lower case R.
If the error message confuses you, let’s break down the error message to understand the jargon. Still, there is a lot of definitions to learn so don’t feel bad if you read the following but still feel confused 
An object reference is required...
Simplified, this means you need a variable.
...to access non-static member...
Simplifed, a non-static member is a variable or function on a class, that isn’t static
.
- A static function requires no object to be called.
- A non-static function requires an object to be called.
Then follow the signature of the function you were trying to call, which was illegal:
UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)
Rigidbody.AddForce is a non-static function, which means you need an object (variable) to call it.
- Rigidbody is a class.
- rigidbody is a reference to an object.
Note: rigidbody component accessor is being phased out and is marked as obsolete. If you want to make your code future proof, consider using GetComponent<Rigidbody>()
instead.