ScreenToWorldPoint- NullRefrenceException

I’m getting a “NullRefrenceException” error with to following line of code:

mousePos = camera.Main.ScreenToWorldPoint(Input.mousePosition);

(playerPos is simply a var, defined in a different spot in the script)

Anyone know why?

Thanks in advance.

1 Answer

1

Use Camera.main (capitalize Camera, lower main) [corrected]

Actually that did not work; I still get the error. -_-

Main is not suppose to be capitalized. So: Camera.main

Actually it's <a href="http://unity3d.com/support/documentation/ScriptReference/Camera-main.html">Camera.main</a>. In the future please check the documentation first. That are some very trivial mistakes... (ps, and be careful what you post as answer to such questions, it could be wrong ;) )

My apologies for propagating error.