instantiate button problem

Hello, what i am trying to do is when i click my GUI button, i want a prefab to be instantiated, then i want to transform it to follow my mouse. Here is my script

var cube2 : GameObject;
var cubetex : Texture;

function OnGUI () {

          var screenPos = Camera.main.WorldToScreenPoint(transform.position); 
          var offset = transform.position -                                                Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z));

      var curScreenPos = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z); 
          var curPos = Camera.main.ScreenToWorldPoint(curScreenPos) + offset; 

    if (GUI.Button(Rect (20,20,60,60), cubetex)) {

        Instantiate(cube2, Vector3(0,0,0), Quaternion.identity);
                cube2.transform.position = curPos;
    }
}

I know that my variables for curPos are right because If i use it on another script i am able to drag objects with it. what i need to know Is that how you transform the object?? i cant get it to move from vector(0,0,0), even when i change (cube2.transform.position = curPos;) to (cube2.transform.position = Vector(14,3,11)), it still stays at 0,0,0. Please help

There are several problems with your script. First, you aren't using Instantiate correctly (see my code below for a correct implementation). Secondly, even if your code worked, you'd only be moving your cube to the mouse position for the one frame in which you click the button. The code below should do the trick; please note, however, that it is untested.

var cube2 : Transform;
var curCube : Transform;

var cubetex : Texture;

function Update() {
    if (curCube != null) {
        curCube.transform.position = curPos;
    }
}

function OnGUI () {

    var screenPos = Camera.main.WorldToScreenPoint(transform.position); 
    var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z));

    var curScreenPos = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z); 
    var curPos = Camera.main.ScreenToWorldPoint(curScreenPos) + offset; 

    if (GUI.Button(Rect (20,20,60,60), cubetex)) {
        curCube = Instantiate(cube2, Vector3(0,0,0), Quaternion.identity);
    }
}

Untested JS, please report any errors