" NullReferenceException: Object reference not set to an instance of an object"

" NullReferenceException: Object reference not set to an instance of an object" error

private var ray : Ray ;
private var RaycastHit : RaycastHit ;

function Update ()
{
if(Input.GetMouseButton(0))
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (Ray.RaycastHit))
{

transform.position.x = RaycastHit.point.x ;
}
}
}

That’s like a world jumble you got there. Seems pretty close, I’m not used to javascript but this seems to be what you’re looking for.

fucntion Update()

{

if(Input.GetMouseButton(0))

{

var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); 

var hit : RaycastHit;

if (Physics.Raycast (ray, hit)) 

  transform.position.x = hit.point.x; 

}

}

thanks this helped