Ray error with touches.position


I have a little piece of code, to make a raycast on the position you touch the screen (iPhone).
I used it in another script, on the exact same way. But now i get an error…

// Buttons
            if (Input.touches*.phase == TouchPhase.Began)*

RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.touches*.position);*
if (Physics.Raycast(ray, out hit, 100, layermaskButtons))
The error is:
> NullReferenceExeption: Object reference is not set to an instance of an object
When i dubble click the error, it says that this line is wrong:
> Ray ray = Camera.main.ScreenPointToRay(Input.touches*.position);*
But I used that exact same line in another script, and that works perfectly!

If the line you mention really is the offending line, I’d guess that your scene doesn’t have a camera that meets the criteria of the Camera.main member.

Note that according to the docs, Camera.main will return null if the specified criteria is not met.