Object reference not set to an instance of an object [help]

Hello guys! as you can read in title, i have this problem, i’m making the survival shooter game tutorial in unity and im getting this error:

NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Move (Single h, Single v) (at Assets/Scripts/Player/PlayerMovement.cs:31)
PlayerMovement.FixedUpdate () (at Assets/Scripts/Player/PlayerMovement.cs:23)

I think that i’m missing an object but i could not find which one…
Here is the full script:

using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLenght = 100f;
void awake ()
{
floorMask = LayerMask.GetMask (“Floor”);
anim = GetComponent ();
playerRigidbody = GetComponent ();
}
void FixedUpdate ()
{
float h = Input.GetAxisRaw (“Horizontal”);
float v = Input.GetAxisRaw (“Vertical”);
Move (h, v);
Turning ();
Animating (h, v);
}
void Move (float h, float v)
{
movement.Set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;

playerRigidbody.MovePosition (transform.position + movement);
}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask)) {
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
playerRigidbody.MoveRotation (newRotation);
}
}
void Animating (float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool (“IsWalking”, walking);
}
}

Please use code tags. They make it simple for everyone to read.

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;

Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLenght = 100f;

void awake ()
{
floorMask = LayerMask.GetMask ("Floor");
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent <Rigidbody> ();
}
void FixedUpdate ()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
Turning ();
Animating (h, v);
}
void Move (float h, float v)
{
movement.Set (h, 0f, v);

movement = movement.normalized * speed * Time.deltaTime;

playerRigidbody.MovePosition (transform.position + movement);
}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask)) {
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
playerRigidbody.MoveRotation (newRotation);
}
}
void Animating (float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool ("IsWalking", walking);
}
}

Also, change awake() to Awake()

playerRigidbody isn’t being defined, so it remains null “Object reference not set to an instance of an object” just means you’re using a value that is null somewhere.

But i defined right here

Rigidbody playerRigidbody;

Right?

No this just means you created a Rigidbody variable called “playerRigidbody” but what does it equal to?

It is equal to “GetComponent ();” right?

void awake ()
{
floorMask = LayerMask.GetMask ("Floor");
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent <Rigidbody> ();
}

But your function is never called because it has to be called “Awake” with a capital ‘A’.
Also have you checked to make sure your object has a rigidbody attached to it?

I was just typing that i fixed by adding the capital ‘A’ hahaha i did not understand, i’m not a pro with english :I Thank you guys! it’s working now