When a masked gunman opened fire at a federal courthouse in Dallas on Monday, longtime Dallas Morning News photographer Tom Fox was already on the scene.

Fox, who was there to get a photo of a defendant in a charter school fraud case, according to the newspaper, captured a photo of the gunman and then immediately hid himself in front of the building. He told USA TODAY he acted on instinct.

“I just kept thinking, 'He's going to look at me around that corner and he's going to shoot,'" Fox told the Morning News, where he's been an employee for 29 years.

Fox added that he thought he “was gone.”

In his account to the Morning News, Fox said he saw a figure once he heard gunshots, but couldn't make out the details. That's when he took out his camera.

"So, I pulled up my long lens and saw someone who I realized was the shooter. And I think, 'Oh my God.' I squeezed off a few frames as he picked something up – a clip, I think – and then I turned and ran," he recalled.

Video of the incident shared on Twitter shows exactly how close Fox was to the gunman. As the gunman approached the front of the courthouse, he appears to exchange fire with people who are offscreen. He is feet away from Fox, who is hiding behind a column and crouching as shots echoed throughout the block.

“I just stood there and prayed that he wouldn’t walk past me,” Fox said in his interview with the Morning News. “Because if he walks past me and sees me, he’s going to shoot me. He’s already got the gun out."

The shooter then runs for the parking lot and the video ends. The gunman was killed on scene. The only other reported injury from the shooting was a federal employee who sustained minor injuries "as she was taking cover from the shooter," according to officials.

Costco shooting:Gunman dead, 2 injured in second California Costco shooting in three days

"And he was just so young. All I could think was 'why?’ There's just too many questions I haven't processed yet,” Fox said. “But this young man, what was it all for? Was it really worth it – for this?"

Fox captured photos of the gunman, wearing a mask and holding a weapon, as well as people running from the scene and law enforcement around the downed shooter. He also took video at the scene.

The newspaper said Fox returned to work in the newsroom Monday.

Fox said, “Your journalistic instincts just kick in."