click and drag clone object!!

hi i got a similar problem here.i m doing a puzzle game and i need to drag a clone object which was randomly array at the bottom of the scene.
this is the script for drag and drop that i did

static var clickedObj : Transform; 
private var offSet : Vector3;     
var cubewall : GameObject;
private var snapAllowance: int = 5;
var linkToArray : Array;

function Update () {
	var ray = camera.ScreenPointToRay(Input.mousePosition); 
	if (Input.GetMouseButtonDown(0)) {    
		var hit : RaycastHit; 
		if (Physics.Raycast(ray, hit, Mathf.Infinity)) {      
			if(hit.collider.gameObject.tag == "Pipe") {
				clickedObj = hit.transform;    
				offSet = clickedObj.position-ray.origin;   
			}
		}
	}

and this is the code for array:

var blockTypes: GameObject[];
var inGamePos: Array = new Vector3[4];
static var clickedObj : Transform; 
var pos1: GameObject;
var pos2: GameObject;
var pos3: GameObject;
var pos4: GameObject;

function Start () {
	
	inGamePos[0] = pos1.transform.position;
	inGamePos[1] = pos2.transform.position;
	inGamePos[2] = pos3.transform.position;
	inGamePos[3] = pos4.transform.position;
	var blockTypesWeight= [2,2,1,1,1,2];
    	
	for (i = inGamePos.length - 1; i >= 0; i--) {
		var ranPipe: GameObject = blockTypes[Random.Range(0,blockTypes.length)];
		var newPipe: GameObject = Instantiate(ranPipe,inGamePos*,Quaternion.identity);*
  •  }*
    

}
i have tried but i couldnt click and drag the pipe that is random arrayed at the bottom even though when i put the pipe to the “Cubewall”, i click and drag around perfectly fine. what i need to do to click and drag the pipe(clone) randomly arrayed at the bottom??

yeah all the pipes in the prefab are tagged with the name tag “Pipe”. The pipe that is already in the hierarchy before the game starts, clicks and snaps into the predefined position perfectly. However the clone pipes that are instantiated in function update are getting stuck to the mouse or if not getting stuck are not snapping to the predefined position.

I now have combined the two scripts, please see code …

var blockTypes: GameObject[];
var inGamePos: Array = new Vector3[4];
var pos1: GameObject;
var pos2: GameObject;
var pos3: GameObject;
var pos4: GameObject;
static var clickedObj : Transform; 
private var offSet : Vector3;     
var cubewall : GameObject;
private var snapAllowance: int = 3;
var blockTypesWeight= [1,1,3,3,1,1];
var SpawnNumber : int = 4;

function Start () {
	
	inGamePos[0] = pos1.transform.position;
	inGamePos[1] = pos2.transform.position;
	inGamePos[2] = pos3.transform.position;
	inGamePos[3] = pos4.transform.position;

		
	for (i = inGamePos.length - 1; i >= 0; i--) {
		var ranPipe: GameObject = blockTypes[Random.Range(0,blockTypes.length)];
		var newPipe: GameObject = Instantiate(ranPipe,inGamePos*,Quaternion.identity);*
  • newPipe.name = “block”;*
  •  }*
    

}

function Update () {

  • var ray = camera.ScreenPointToRay(Input.mousePosition);*

  • if (Input.GetMouseButtonDown(0)) {*

  •  var hit : RaycastHit;* 
    
  •  if (Physics.Raycast(ray, hit, Mathf.Infinity)) {* 
    
  •  	if(hit.transform.gameObject.tag == "Pipe") {*
    
  •  		clickedObj = hit.transform;* 
    
  •  		offSet = clickedObj.position-ray.origin;* 
    
  •  	}*
    
  •  }*
    
  • }*

  • else if (Input.GetMouseButtonUp(0)) {*

  •  	if(clickedObj != null&& clickedObj.GetComponent(BlockScript).hitObj != null){*
    
  •  		if(clickedObj.gameObject.transform.position.x>=clickedObj.GetComponent(BlockScript).hitObj.transform.position.x-snapAllowance && clickedObj.gameObject.transform.position.x<=clickedObj.GetComponent(BlockScript).hitObj.transform.position.x+snapAllowance)*
    
  •  	snap(clickedObj.gameObject,clickedObj.GetComponent(BlockScript).hitObj.transform.position);*
    
  •  	clickedObj = null;*
    
  •  }* 
    
  • Spawn();*

  • }*

  • if (clickedObj) {*

  •  clickedObj.position = Vector3(ray.origin.x+offSet.x, ray.origin.y+offSet.y,clickedObj.position.z);* 
    
  • }*
    }

function snap (objToSnap: GameObject, posToSnap: Vector3) {

  • print(“snap object”);*
  • objToSnap.transform.position.x = posToSnap.x;*
  • objToSnap.transform.position.y = posToSnap.y;*
  • clickedObj.GetComponent(BlockScript).hitObj = null;*

}

function Spawn (){

  •  	if (pos1.Vector3 != GameObject.Find("block").Vector3){*
    
  •  		var ranPipe: GameObject = blockTypes[Random.Range(0,blockTypes.length)];*
    
  •  		var newPipe: GameObject = Instantiate(ranPipe,inGamePos[0],Quaternion.identity);*
    
  •  	}*
    

}

yeah… it work now… cheer…