An object reference is required
I started using unity and making Roll-a-ball i finish the script but i get this message
"Assets/Script/PlayerController.cs(18,19): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)'"
Anyone,can help me ?
This is my script
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
//Use this for initilization
void Start () {
}
//Update is called once per frame
void FixedUpdate (){
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, 0.0f, moveVertical);
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
Rigidbody.AddForce(movement);
}
}
Answer by Whitecold · Nov 29, 2015 at 12:54 PM
Rigidbody is the name of the class, and rigidbody is the variable referencing the rigidbody object of a gameObject. Try lowercase rigidbody, and it should work.
Your answer
![](https://koobas.hobune.stream/wayback/20220612050732im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Como puedo hacer que un objeto se active dependiendo de otros 4 0 Answers
Unity Freeze on "Play" 0 Answers
Unity cant open script!! 0 Answers
LAUNCH PROBLEMS UNITY 3D 1 Answer
[SOLVED] I can not login to Unity and Asset store after format my PC 0 Answers