How to add a Object Reference

Hey there,

I’m pretty new to this Unity stuff and C#, I’m still learning. I’ve had a google, but I’ve had no luck finding what I need. Basically, I’m having an issue in line 22. The issue is as follows,

error CS010: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)’

I understand what it means I think, but unsure how I can actually fix the issue. Below, is my entire script and I hope you guys can help me out. :slight_smile: Thanks! Also would be great, if you can spot any other issues…

using UnityEngine;
using System.Collections;

public class Jump : MonoBehaviour {

	//Controls Player Jump Height
	private int jumpHeight = 500;
	void Start () {

	void Update () {

		if (Input.GetButtonDown("Jump") || Input.GetKey ("w")) {

	void DoJump (){
		Rigidbody.AddForce(new Vector3(0, jumpHeight,0), ForceMode.Force);

You should use:

rigidbody.AddForce(new Vector3(0, jumpHeight,0), ForceMode.Force);

i.e. rigidbody with lower case ‘r’ to refer to the Rigidbody component attached to the player GameObject.

Otherwise Unity doesn’t know to which Rigidbody instance you are referring to.