mouse move,click

#pragma strict

var myCamera : Camera;

function Start () {


function Update () {

var vec : Vector3 = myCamera.ScreenToWorldPoint(Input.mousePosition);
var side : float = 8.0;
var top : float = 9.0;
vec.x = Mathf.Clamp(vec.x, -side, side);
vec.y = Mathf.Clamp(vec.y, -top, top);
vec.z =  0.0;
transform.position = vec;


this is script is for moving cube(gameobject) using mouse ,this script is running in ortho projection, can u tell me how to run in perspective and how can i throw cube in a projectile motion using a click

If the camera is axes aligned (Rotation of (0,0,0) will work), you can supply the distance in front of the camera for the ‘ScreenToWorldPoint()’ calculation. For example, if your camera is at ‘z’ = -10, and your object to move is at ‘z’ = 0.0, you can do:

var vec : Vector3 = Input.mousePosition;
vez.z = 10;
vec = myCamera.ScreenToWorldPoint(vec);

If the camera is at an angle with respect to the axes, then you need to approach this problem differently with some form of Raycast. For a flat surface, you can use Unity’s mathematical Plane class and Plane.Raycast(). For a terrain, you would use Collider.Raycast() or Physics.Raycast().