I'm trying to create a 2d game and the game objects should follow the mouse on a single axis (the x axis), when the user drags the object.
Here's my code, the problem is, that the game object flies out of the screen as soon as i try to drag it, instead of following the mouse,
Help would be much appreciated.
asked Mar 10 '11 at 02:14 PM
instead of gameObject.transform.Translate(... do a gameObject.transform.positon = point...or whatever you want to set it to.
Translate moves the object, at its current position, by some amount. You want to set the position to the position of the mouse so you can just set the position directly.
You should really cache the transform of the object in a start or awake function. check out caching in the docs.
answered Mar 10 '11 at 03:07 PM