[Solved ]unity on mouse click how do i do it?

i come across a little problem and i been trying to search ages for it. i want to be able to attach a gameobject to the mouse by clicking on it…

i do not wish to let go of the gameobject before i click again. and i want to do it without holding the mousebutton down?

is it possible?

Of course it’s possible.
I’d probably create a bool and call it ‘followingMouse’. Then in the OnMouseDown() function toggle that (followingMouse = !followingMouse). In Update() use an if-clause to ask if followingMouse is true. If it is, set the position to the mouse’s position.

1 Like

Don’t forget a collider on the target object.

1 Like

oh nice thanks it works