I am using a Raycast from my mouse position to select an object in 3d space but my code is coming up with error NullReferenceException: Object reference not set to an instance of an object CameraControl.CameraSelect () (at Assets/Scripts/CameraControl.cs:32)
here is my code
void CameraSelect() {
RaycastHit rayHit;
if(Input.GetButton("Fire1")){
Debug.Log(curCam);
Ray ray = Camera.current.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out rayHit,9999)){
curCam.enabled = false;
tarCam = rayHit.transform.gameObject.GetComponentInChildren< Camera >();
tarCam.enabled = true;
}
}
}
it seems that my ray initialization is giving me the error, that is line 32, but from what i can tell my code is correct? please help
the error is on line 5 of the code snippet