Mouse driven control of an object in 3d world

I have a sphere in my world. As soon as the mouse pointer enters the world, i want the sphere's transforms to be guided by the mouse movement.In other words, the sphere should move based on mouse movements. I was trying this out looking at various other mouse-related posts and ended up with the below code , which gives me errors

var myGameObject: GameObject;
function Update () {
    handleMouse();
}

function handleMouse()
{
    Vector3 ObjPosAtStart = myGameObject.transform.position;
    Vector3 MouseBegin = camera.main.ScreenToWorldPoint(Input.mousePosition);
    ObjPosAtStart = MouseBegin;
    Vector3 MousePos = camera.main.ScreenToWorldPoint(Input.mousePosition);
    myGameObject.transform.position = MousePos;
}

myGameObject is supposed to be my sphere.

I am not able to attach this script to sphere as it gives me errors about missing semicolans!

Any thoughts appreciated

You probably want to have a look at: Screen.lockCursor which will hide and lock the mouse position.

You can then use Input.GetAxis to read the mouse X and Y input, like this:

var horizontalSpeed = 2.0;
var verticalSpeed = 2.0;

function Update ()
{
    // Get the mouse delta. This is not in the range -1...1

    var h = horizontalSpeed * Input.GetAxis ("Mouse X");
    var v = verticalSpeed * Input.GetAxis ("Mouse Y");

    transform.Translate (h, 0, v);
}

This will give you some very basic movement along the X-Z plane which corresponds to your mouse movement.

If you want controls a little more like "Marble Madness" - i.e. where the movement of the mouse adds a force to the game object, you could replace "Update" with "FixedUpdate", and relplace the line:

transform.Translate (h, 0, v);

with:

rigidbody.AddForce(h, 0, v);

Or even better, to convert the H and V to a force relative to the camera's orientation:

Vector3 localForce = camera.TransformDirection(new Vector3(h, 0, v));
localForce.y = 0;
rigidbody.AddForce(localForce);

Hopefully this gives you enough to chew on for now :)

Your code isn't using valid Javascript syntax. For variable declarations, replace "Vector3" with "var". The variables will still be typed as Vector3 because of type inference. You can explicitly write "var ObjPosAtStart : Vector3 = ...", but that's not necessary.

As a side note, it's a good idea to keep your names consistent with conventions, in order to have more readable code. i.e., use lowercase for variable names, and uppercase for classes and functions.