how to get the object reference to an object

trying to make a horror game, and trying to make it when they look at the trash and hold mouse 0 they can clean it up. I’m new to unity and coding and I cant figure out how to work with raycast. I keep getting a object reference error. heres my code

public class GarbageRaycast : MonoBehaviour
{
[SerializeField] private LayerMask PickupLayer;
[SerializeField] private Camera PlayerCamera;
[SerializeField] private float pickupRange;
[SerializeField] private KeyCode UseKey = KeyCode.Mouse0;
[Space(10)]
private BoxCollider CurrentboxCollier;
private GarbageController garbageController;
[SerializeField] private Image crosshair = null;
private bool isCrosshairActive;
private bool doOnce;

void Update()
{

   
    Ray Pickupray = new Ray(PlayerCamera.transform.position, PlayerCamera.transform.forward);

    if (Physics.Raycast(Pickupray, out RaycastHit raycastHit, pickupRange, PickupLayer))
    {
        if (CurrentboxCollier)
        {

        }
        else
        {
            if (!doOnce)
            {
                garbageController = raycastHit.collider.gameObject.GetComponent<GarbageController>();
                CrosshairChange(true);

            }

            isCrosshairActive = true;
            doOnce = true;

            if (Input.GetKeyDown(UseKey))
            {
                garbageController.PlayGarb();
            }
        }
    }
    else
    {
        if (isCrosshairActive)
        {
            CrosshairChange(false);
            doOnce = false;
        }
    }

}
void CrosshairChange(bool on)
{
    if (on && !doOnce)
    {
        crosshair.color = Color.red;
    }
    else
    {
        crosshair.color = Color.white;
        isCrosshairActive = false;
    }
}

}

if anyone know how to fix, or help that would be great!