How to round the coordinates of a game object to an integer or "nice" number?

I am trying to make a very basic snap to grid (and only on the X axis) but the Round function isn’t quite working for me.

void Update () {

I was wondering if there’s another way, or I’m just doing something wrong here?

Yes, you do something wrong here. RoundToInt is a method that returns the rounded value as integer. In your code you don’t do anything with the returned value. If you want to actually move the objects to the rounded position you have to do this:

Vector3 tmp = transform.position;
tmp.x = Mathf.Round(tmp-x);
transform.position = tmp;

Note that you have to use an actual temporary variable as you can’t directly change only one component of transform.position as it’s a property (getter and setter combo) and Vector3 is a valuetype.

Also note that i did not use RoundToInt as this would be pointless. A Vector3 consists of floating point numbers. So you could use RoundToInt but it would have to convert the returned integer back to a float anyways. So just using Round is enough.