If the positions of objects need to be restricted to specific increments, it is useful to have a grid drawn in the Scene window to help ensure that new objects are positioned based on those values, as well as code to snap objects to that grid.
In this recipe, we'll use Gizmos to draw a grid with a customizable grid size, color, number of lines, and line length. The result of following this recipe will look as follows:
Figure 13.3 – Example of a visible grid that objects snap to