hi every one
i do not understand what is wrong with my script as it is exactly the same as unity’s tutorial’s one
plz help:
Assets/scripts/PlayerMovement.cs(13,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)’
thanks Evenus1
You need to reference the rigid body you want to move.
here is my script:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis (“Horizontal”);
float moveVertical=Input.GetAxis(“Vertical”);
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
Rigidbody.AddForce(movement);
}
}
could u plz tell me which bit to change
You need to store a reference to the rigid body , or the game object its on (and then use get component).
Like the example in the docs
this is still very confusing. and i have followed a tutorial that i watched work made by unity so why is it not right.
Just adjust your code to reference the rigid body on the object, as demonstrated in the example I linked.
i don’t get it as i don’t get c#
thank you all i now understand