Camera.main is null when performing raycast
The only thing that can return null in your code is Camera.main.ScreenToWorldPoint. It means that Camera.main is null. For Camera.main to be initialized, the camera must have the MainCamera tag. Select the Camera GameObject then change the tag to MainCamera. If you don’t want your camera to be in the MainCamera tag, you can also … Read more