Why can I not get an erection when I need one

From time to time I have difficulty in getting an erection when I need it.
We was in the shower the other day playing and I was very hard left the shower as she didn’t want to carry on in there and I lost it with In 2 minutes I then tried to thumb in a softy which pissdd me off big time.
She said let’s carry on later but I was just mega pissdd off with myself and didn’t try for anything for the rest of the weekend.

I hope talking about it may/ will help others talk about what they do in that situation.