Touch not registering

I am getting this error message each time I touch an object on an ios platform with the remote app.

NullReferenceException: Object reference not set to an instance of an object
test-unity-5.Update () (at Assets/my-scripts/test-unity-5.js:14)

I don’t know how to solve it, and don’t even know why it is occurring. ( I have a general idea, but…)

My code is:

#pragma strict
 private var JumpH = 8;
// Jump Hieght 8 units
private var IsFalling = false;
// Is not falling start
                                                                            

var particle : GameObject;
function Update () 
{
    for (var touch : Touch in Input.touches) {
        if (touch.phase == TouchPhase.Began) {
                                                                           
            var ray = Camera.main.ScreenPointToRay (touch.position);
            if (Physics.Raycast (ray)) {
                                                                           
               //ad effects here
             rigidbody.velocity.y = JumpH;
             IsFalling = true;   
          
            
            }
        }
    }
}

I am touching a button I imported that is stacked in the camera, my player’s view.
I am new to unity, so please don’t be spiteful. Any help is appreciated!

There are two object references on line 14. One is Camera.main, and the other is touch. The error message is telling you that one of them is null.

Give that you are iterating through Input.touches, which should only give you an array of touches in the current frame, it seems unlikely that touch is null. My deduction would therefore be that Camera.main is null. Do you have a camera in your scene that is tagged as “MainCamera”?