In StarCraft II, the Protoss defensive structure that attacks nearby enemies is the Photon Cannon.
Photon Cannons are static Protoss defenses that can attack both ground and air units. They require a Pylon to provide power, although the cannon itself is built by a Probe at a suitable location. Their ability to target both major unit types makes them more versatile than defenses restricted to ground or air combat.
The Photon Cannon also provides detection, allowing it to reveal cloaked or burrowed units within its detection range. This makes it useful against threats such as Terran Banshees, Dark Templar, and burrowed Zerg units. Cannons are often positioned near mineral lines, ramps, or important structures.
Players sometimes confuse the Photon Cannon with the Pylon. A Pylon supplies power and increases Protoss supply, but it does not attack. The cannon is the actual defensive weapon, while the Pylon usually enables its construction and operation.