Greetings fellow Unity types…
I am using the CameraRayCaster.cs down loaded from the course, when I run it with the Cursor.cs that Ben makes in the video, I get the following errors:
NullReferenceException: Object reference not set to an instance of an object
CameraRaycaster.RaycastForLayer (Layer layer) (at Assets/Scripts/CameraRaycaster.cs:52)
CameraRaycaster.Update () (at Assets/Scripts/CameraRaycaster.cs:35)
This appears to be the offending section:
RaycastHit? RaycastForLayer(Layer layer)
{
int layerMask = 1 << (int)layer; // See Unity docs for mask formation
Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; // used as an out parameter
bool hasHit = Physics.Raycast(ray, out hit, distanceToBackground, layerMask);
if (hasHit)
{
return hit;
}
return null;
}
Any thoughts/resolutions?
Many thanks in advance.