How to pick up object on touch?

So I’m trying to pick up a flashlight when the user is both touching the screen and the ray is hitting the flashlight. Obviously it doesn’t work, but there arent any errors that prevent the game from playing, all it says is:
NullReferenceException: Object reference not set to an instance of an object Ray.Update () (at Assets/Scripts/Ray.js:23)

I used to have gameobject.tag, and they matched up, but it still said that, sorry for the poor explanation. Any help would be greatly appricated, I’m new to IOS programming in Unity, but pretty experienced with Unity in all. Thanks, here is the script I used:


#pragma strict

function Start () {

}
var guiray : GUIText;
var flashlight : GameObject;
var flashlightdesk : GameObject;
function Update () {
      var hit : RaycastHit;
var ray = camera.ScreenPointToRay (Vector3(200,200,0));
     Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
       var fwd = transform.TransformDirection (Vector3.forward);
    if (Physics.Raycast (transform.position, fwd, 10)) {
     //   print ("There is something in front of the object!");
  //  var fingerCount = 0;
 //   for (var touch : Touch in Input.touches) {
 //       if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
   //         fingerCount++;
 //   }
  //      if (fingerCount > 0){
  //      print ("User has " + fingerCount + " finger(s) touching the screen");
if(hit.collider.gameObject.name == flashlightdesk) {
guiray.text = "Pick Up Flashlight"; 
    if (Input.touchCount > 0) {
   //place pick up code here!
   flashlight.gameObject.active = true;
      //flashlight.gameObject.enabled = true;
   flashlightdesk.gameObject.active = false;
}
}
else {
guiray.text = "";
}
}
}

On first glance it looks like you did not use your Raycast “Hit” variable in your raycast. Try something like this:

if (Physics.Raycast(ray, out hit, 100)

I don’t know if the out is required in java this is C# example.