- Home /
How to make a gameobject follow the mouse when I click and drag on the object.
I'm trying to get it so when I click on my gameobject and move the mouse/touch (since this will be a game for android) then the gameobject should follow the mouse/swipe until the user lets go. Is their any simple way to do this? I have heard about using OnMouseDrag, but I can't really figure it out.
Answer by siaran · Feb 28, 2015 at 03:36 PM
So, convert your mouse screen position to world space, then move your object towards the location in world space?
What exactly is your problem?
I want it only to follow the mouse when I click on the object first, and continue moving as long as the mouse is held down
Well, you'd check if you clicked on the object when you click the mouse with Input.On$$anonymous$$ouseButtonDown, and if so could set some boolean 'clickedobject' to true, then have code that moves your object towards the mouse while it is true, and set it to false again with Input.On$$anonymous$$ouseButtonUp.
Your answer
Follow this Question
Related Questions
Joystick movement Android 2D 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity on Android? 2 Answers
LitJSON android problem 1 Answer