Grid snap

Here are a few simple lines of code that will allow you to snap objects to a grid. [gridSize] must be defined beforehand and can be anything above 0, but values between 1 and 5 are recommended. [mousePos] can be any position vector (like a raycast position), but I am using mouse position for this example.

http://i.imgur.com/1GiML7g.jpg

With this code, you can create an object at [GridPos] when mouse is clicked and it will be snapped to a grid.