When something happens that's never been a problem before, it's natural to be upset and imagine the worst. Many men have occasional periods of impotence. However, few men feel comfortable talking about impotence, so it's easy to feel like you're the only one when it happens to you. Find a good physician and have yourself thoroughly checked out for possible medical causes. There are all kinds of possibilities.
Impotence is a side effect of some medications.
If the impotence is not due to a medical problem, then find a good psychotherapist. Make sure it's someone who is competent to treat the problem and will consider all possible reasons for it. Also, make sure it's someone who will not jump to the conclusion you are not really gay after all. Finally, be gentle with yourself while you look for solutions. Blaming yourself will only make you feel worse and won't solve the problem.