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