- Home /
GameObject drags with mouse?
I have been trying to write a javascript that will make a game object's position in the same position of the mouse without clicking to drag it.
Here is what I wrote:
var theObject : Transform;
var positionOfMouse : Vector3;
function Update(){
positionOfMouse = Input.mousePosition;
theObject.transform.position = lastMousePosition;
}
The problem is that the position of the mouse is shown by pixels and the object will move with what the positionOfMouse variable is. I cannot figure out a way for it to move exactly with the mouse. Could someone help me with making a script that will cause the object to be in the location of the mouse? Thanks.
Answer by Tetrad · Jun 26, 2010 at 12:57 AM
I mentioned that I do not want to click it and that I just want it to always be in the position of the mouse.
The reason for your problem -- and the solution -- are the same as in that question. The only difference between the two is that you're not checking to see if the mouse button is down.
I am not sure what to replace "(Input.Get$$anonymous$$ouseButton(0))" with so that it is without pressing the mouse button.
Never $$anonymous$$d I tried just (Input) and it does what I want it to do.