A 31-year-old man suspected in the ambush killing of a police detective in Texas has apologized to the officer's family and said he "lashed out" in anger after several custody battles.

Otis McKane was arrested on Monday for the killing of 50-year-old Benjamin Marconi, a 20-year veteran of the San Antonio force who was gunned down a day earlier as he sat in his squad car outside the department's headquarters.

As he was escorted by officers outside the building late on Monday, McKane told reporters he had been involved in several custody battles.

"I just want to see my son ... The situation I was in, I lashed out at somebody who didn't deserve it," he said, without saying directly that he killed Marconi.

Asked by reporters whether he had any message for the slain officer's relatives, McKane replied: "I'm sorry."

The detective was shot twice in the head as he wrote a traffic ticket on Sunday morning. Authorities said the shooter stopped his car behind Marconi's vehicle, walked up and shot the detective through the window, police said.

Marconi was one of four officers shot in the line of duty in Texas, Missouri and Florida on Sunday. A total of 57 U.S. law enforcement officers have been killed by gunfire so far this year, a 68 percent increase from the same period in 2015.

San Antonio Police Chief William McManus said McKane is responsible for the detective's "cold calculated murder."

Police said they used a photo of the suspect's car and surveillance video to track down McKane, who was arrested without incident on Monday in an auto that he was traveling in with a woman and a 2-year-old child.

The video showed McKane pacing in front of the locked doors of the police headquarters about four hours before the shooting. He was let in and spoke with someone on the intercom, police said, and then he walked out about 20 seconds later.

McManus said McKane talked to a clerk inside the otherwise deserted building, then suddenly said "never mind" and left.

In a statement, Marconi's family thanked police and the local community "for the outpouring of prayers, support, and love we have received."

(Additional reporting by Brendan O'Brien; Editing by Daniel Wallis and W Simon)