- Home /
Question by
St4rKiller070 · May 25, 2013 at 09:12 AM ·
nullreferenceexceptionscreenpointtoray
NullReferenceException in Camera.main.ScreenPointToRay
Hi, I need help. I redeveloped my game a bit. Everything is ok, but when I run this part of code:
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
In debug console appears error: "NullReferenceException". It seems that Camera.main or Input.mousePosition are null. Do you have any idea: why? Earlier it worked fine.
Comment
The Camera.main property looks for a Camera in the scene with the "$$anonymous$$ainCamera" tag. Check that your camera is tagged correctly.
Answer by konsnos · Mar 04, 2014 at 06:05 PM
You have to set a camera with the tag 'MainCamera'. For more information check the doc of Camera.main.
In case you have added more cameras they don't come with this as the default tag.