Moons ago in an exercise a low flying US Skyraider appeared and came towards our carrier. A ( no guns) Vixen intercepted but couldnt get a missile lock so couldnt shoot it down. The eventual solution was to have fired a whole pod of air-ground rockets.
Guns are also useful in ground attack roles.