How far do you have to be away from a building in California when shooting a gun?
That is a vague question. Indoor rifle ranges are buildings--you
can fire inside them, you can return fire in self-defense, If you
are a peace officer, you can fire on a criminal under circumstances
where your safety is at risk. It is usually illegal to discharge a
fire arm within city limits so, firing an air rifle would not
necessarily break that law. If you own the property, and it is
outside city limits, you could fire off your back porch (if it is
safe to do so) without breaking a law.