Anything that thins the blood will affect an erection. The most common culprits are blood pressure medications, which is a good enough reason to watch your weight, exercise regularly and generally keep fit and healthy so you don't get cursed with impotence.
And if so cursed, sometimes medications may get you hard, but for enough men they don't work at all.