Unity : ドラッグでオブジェクトを動かす

シーンに配置したオブジェクトをマウスなどのドラッグ操作によって移動するには OnMouseDrag メソッドを利用するのが楽です。 ただし OnMoouseDrag メソッドを利用する場合は、対象のオブジェクトに Collider が付与されていることが必須なので注意してください。
例えば次のサンプルクラスをオブジェクトに付与すると、 マウスなどのドラッグ操作によって位置を移動することができるようになります。
using UnityEngine;
public class MouseDrag : MonoBehaviour
{
void OnMouseDrag()
{
Vector3 objectPointInScreen
= Camera.main.WorldToScreenPoint(this.transform.position);
Vector3 mousePointInScreen
= new Vector3(Input.mousePosition.x,
Input.mousePosition.y,
objectPointInScreen.z);
Vector3 mousePointInWorld = Camera.main.ScreenToWorldPoint(mousePointInScreen);
mousePointInWorld.z = this.transform.position.z;
this.transform.position = mousePointInWorld;
}
}
ここでは Z 方向への移動は行わないものとしています。並行投影(Orthographic)の場合は不要ですし、 透視投影(Perspective)の場合にも、Z 方向への移動はユーザが知覚しにくいので多くの場合には不要でしょう。 ドラッグ操作ではなく、Leap などを使った 3 次元方向への操作の場合はまた別の実装が必要ですし。
またここでは main のカメラが描画した画面からオブジェクトを操作しています。 それ以外のカメラの時には、コードの該当箇所を対象のカメラに変更してください。