Hi, i would like to know how to drag an object with the mouse only to the X and Y axis.
Most important i need this object snapped to a grid (of 2 unit for example), the pivot point of the game object is at left bottom.
During the drag when the object is close enought to the next grid point I needt that the object move to the next point.
I fount this wiki but it works different:
Tnanks in advance
At edit time or run time?
At edit time, set the Snap Settings as described in Positioning GameObjects.
At run time, keep track of the world position, but round it up or down to the nearest unit size. The example below rounds to one unit:
Vector3 worldPos = <smooth position in world>
transform.position = new Vector3(Mathf.Round(worldPos.x), Mathf.Round(worldPos.y), worldPos.z);
Exactly! if you try to replace the variables with the values you will see that the operation is correct