IphoneInput function, Need your helps

I would like to touch on one object in a lots objects in the scene and that object should be follow to the touch.iPhoneTouchPhase.Moved by mousePosition on the screen. hmm I stuck now. I have no idea on it. Please help.

thanks for advance.

You can convert a screen position to a point in the camera’s coordinate space by using Camera.ScreenToViewportPoint on the touch position. Then, you can set the Z coordinate of this point to the desired distance from the camera and use Camera.ViewportToWorldPoint to get the point in space. Unfortunately, I haven’t been able to test the following code, but it should at least get you started:-

var target: Transform;
var distFromCamera: float;


function Update () {
	var touch = iPhoneInput.touches[0];

	if (touch.phase == iPhoneTouchPhase.Began) {
		var hit: RaycastHit;
		var ray = Camera.main.ScreenPointToRay(touch.position);
		
		if (Physics.Raycast(ray, hit)) {
			target = hit.transform;
		}
	}
	
	if (target  (touch.phase == iPhoneTouchPhase.Moved)) {
		var pos: Vector3 = Camera.main.ScreenToViewportPoint(touch.position);
		pos.z = distFromCamera;
		target.position = Camera.main.ViewportToWorldPoint(pos);
	}
	
	if (touch.phase == iPhoneTouchPhase.Ended) {
		target = null;
	}
}