x


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.

more ▼

asked Jun 26 '10 at 12:25 AM

0V3RWR173D gravatar image

0V3RWR173D
190 10 11 25

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
more ▼

answered Jun 26 '10 at 12:57 AM

Tetrad gravatar image

Tetrad
7.3k 27 37 89

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.

Jun 26 '10 at 01:18 AM 0V3RWR173D

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.

Jun 26 '10 at 01:47 AM Tetrad

I am not sure what to replace "(Input.GetMouseButton(0))" with so that it is without pressing the mouse button.

Jun 26 '10 at 10:55 PM 0V3RWR173D

Never mind I tried just (Input) and it does what I want it to do.

Jun 26 '10 at 11:08 PM 0V3RWR173D
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1001
x915
x59

asked: Jun 26 '10 at 12:25 AM

Seen: 1826 times

Last Updated: Jun 26 '10 at 12:25 AM