You can't effectively repair individual scratches with spray paint. Spray paint is only useful when covering a relatively large area, which has to be sanded flat first and blended at the edges of the treated area with the rest of the paint.
There's no "hardcoded" ideal distance for spraying either. The ideal distance depends a lot on the pressure in the can, the atomizer, and the thickness of the solution. Generally it's about a foot or a foot and a half, but could be less or more, depending on said factor. What's important is that 1. you don't spray it on too thick, because if it runs, you've to start over; 2. but you've to make sure that you get even coverage.
It's usually useful to try spraying on a sheet of paper first, to see how the paint is coming out of the can (and to get rid of the fully or partially dried particles / chunks of paint from the atomizer, which if lands on the paint surface, will show as small bumps and again, ruin your paint). Also, try spraying very thin first, because you can always go multiple times over the same area, but if you put too much on, it will run, and you won't get a flat surface.