Can anyone figure out whats wrong with this script? It keeps saying NullReferenceExeption.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerLocomotion : MonoBehaviour
{
InputManager inputManager;
Vector3 moveDirection;
Transform cameraObject;
Rigidbody playerRigidbody;
public float movementSpeed = 7;
public float rotationSpeed = 15;
private void Awake()
{
inputManager = GetComponent();
playerRigidbody = GetComponent();
cameraObject = Camera.main.transform;
}
public void HandleAllMovement()
{
HandleMovement();
HandleRotation();
}
private void HandleMovement()
{
moveDirection = cameraObject.forward * inputManager.verticalInput;
moveDirection = moveDirection + cameraObject.right * inputManager.horizontalInput;
moveDirection.Normalize();
moveDirection.y = 0;
moveDirection = moveDirection * movementSpeed;
Vector3 movementVelocity = moveDirection;
playerRigidbody.velocity = movementVelocity;
}
private void HandleRotation()
{
Vector3 targetDirection = Vector3.zero;
targetDirection = cameraObject.forward * inputManager.verticalInput;
targetDirection = targetDirection + cameraObject.right * inputManager.horizontalInput;
targetDirection.Normalize();
targetDirection.y = 0;
Quaternion targetRotation = Quaternion.LookRotation(targetDirection);
Quaternion playerRotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
transform.rotation = playerRotation;
}
}

NullReferenceException means you are trying to access a part of something which is a null value. Easily one of the most common and most google-able problems you will run into. Not only that, the full error will tell you which line it occurs on, after that, you only need to narrow it down yourself to figure out what’s null.

On a second note, when posting code in the Scripting Forum, make sure to use Code Tags to make your code easier to read for anybody that wants to help you.