How to click and drag an object with my current code

The code I have here I need it to be able to click and drag on object. But as far as i can get is clicking the object and it moves once but thats it. Then i have to click again and it moves once again but doesn’t follow the mouse. Heres my code

#pragma strict
static var objectNumber 		: int; // changes for every object created. Used for makeing each object unique
private var thisObjectsNumber   : int;	// makes the static variable a non changing private varaible
private var objectName 			: String;		// the name for all objects.
 var selectedObject 		: GameObject; // var for your selected object. This is the object that gets changed.
private var thisObject 			: GameObject;	// sets the game object to this script
 var move				: boolean;
function Start () 
{
	// Gives every object its uniqe name when its created.
	objectNumber += 1;
	thisObjectsNumber = objectNumber;
	objectName = gameObject.name + "# " + objectNumber; 
	thisObject = gameObject;
	thisObject.name = objectName;
}

function Update () 
{
	EditMode();

}


function EditMode()
{
	
	if(Input.GetMouseButtonDown(0))
	{
		var hit : RaycastHit;
		var ray : Ray = camera.main.ScreenPointToRay(Input.mousePosition); 
		if(Physics.Raycast(ray,hit,100))
		{
			// makes sure to not nullify your object when you click off of it
			if(hit.transform.tag == "Game Object")
			{
				if(hit.transform.name == objectName)
				{
					selectedObject = GameObject.Find(objectName);
				}
				
				if(hit.transform.name != objectName)
				{
					selectedObject = null;
				}
			}
			
			if(move == true)
			{
				if(hit.transform.gameObject == selectedObject)
				{
					
					selectedObject.transform.position.x = hit.point.x;
					
										
				}
			}
		
		}
		
	}
}

So this is how I would do it in C#, sorry for not being in JS, but it should translate just fine:

What I have done in the past is have a GameObject variable where I store what is being dragged. When we click we store the variable, when the mouse is released, we null the variable.

We also do a check if (movingObject != null) and we move that object to where the current mouse position is. If you want the object to be forced on a certain axes or area, you can always clamp the values as you need to. Hope this helps.

private void EditMode(){
  if (Input.GetMouseButtonDown(0)){
   Ray raytest = Camera.main.ScreenPointToRay(Input.mousePosition);
   RaycastHit hit;
  if (Physics.Raycast(raytest, out hit, 100)){
    movingObject = hit.gameObject; //or whatever you name that variable
  }

  }

  if (Input.GetMouseButtonUp(0)){
    movingObject = null;
  }

  if (movingObject != null){
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    movingObject.transform.position = mousePos;
  }


}