The 38-year-old man had been spearfishing with friends when he was attacked on a coral reef off Rottnest Island, police said.