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.

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.