The following lines of code give a Null Exception Error:
I did some research and realize that there has to be a main camera (which is the first one enabled). I only have one camera enabled but went ahead a made a script to enable the "main" camera. This line of code still does not work, and I don't know why...
Can there be another reason for a Null Reference?
asked Apr 19, 2012 at 07:06 AM
The 'main' camera is actually a pretty fuzzy definition. What 'Camera.main' actually does, is return the first active camera tagged 'MainCamera'. If you have a camera, but it doesn't have that tag, it won't work!
I recommend that you create a public variable in your script to which you can attach the camera in the editor. This way you can be sure that not only is it the right camera, it won't ever create a null-reference exception.
answered Apr 19, 2012 at 07:14 AM