Electron affinity is also known as electron gain enthalpy.
In case of non metals electron gain enthalpy decreases down the group, as the size of the atom increases down the group therefore the force of attraction towards the incoming electron also decreases( with some exceptions).
Whereas along the period, electron gain enthalpy increases because the size of atom decreases and hence force of attraction towards the incoming electron also increases ( excluding few exceptional cases).