- Home /
dragging out an object from mouse click?
hey all, im trying to create a script that enables an arrow to be spawn when the user holds down a mouse button and then disapear when the mouse is released. easy enough right?
now this i can do no problem but im struggling to get the effect i want which is the arrow to grow and be dragged out as the user moves the mouse while the button is down.
ive made a small image to help show what im after http://i.imgur.com/2UXRl22.png
point A is mouse down point B is mouse up
ive tried a few ways to get this working but none of which work correctly with a orpographic camera . the arrow grows in size from 0 to the distance from point a to point b
any help would be great
Answer by darthbator · Sep 18, 2013 at 08:37 PM
Poll the screen space position of the mouse on getMouseButtonDown() and then in update if (Input.getMouseButton()). Use Vector2.Distance to get a float that you can then use to scale the object as you desire. That's how I would do something like this. You can also at the end of update get a "deltaDistance" for how far the mouse has moved which will give you even more granular control. To do this just save the last position from and update and subtract it from the current position to get the delta.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Drag item on screen once spawned. 0 Answers
Spawn prefab where i click. 1 Answer
Problem with Intantiate using uLink! 2 Answers
Mouse Click and Spawn object 4 Answers