With a gameobject cursor, what would be the best way to get it to follow the real cursor, but locked to a grid?

I am trying to develop a simple solution to get my gameobject cursor following the real cursor within a limited grid. It should be locked to the grid so it doesn’t move diagonal, just left/right, but follows the cursor along the path it’s moved in. Has anyone seen solutions that would help with this?

If you require cursor to jump between grid points, then you can use this sample solution:

public GUITexture cursor;
private float gridSize = 50f;

void Update()
{
    var x = Mathf.RoundToInt(Input.mousePosition.x / gridSize) * gridSize;
    var y = Mathf.RoundToInt(Input.mousePosition.y / gridSize) * gridSize;

    var rect = cursor.pixelInset;
    rect.x = x - Screen.width / 2;
    rect.y = y - Screen.height / 2;
    cursor.pixelInset = rect;
}