How can I fix this randomly rotating gun to an unknown degrees?

I’m sorry I am bad at English* and beginner on unity

So I have this gun and i want to flip it as soon as the gun points towards 90 degrees and turn the flip off when it goes 270. But turns out that my gun points to random position and i don’t know what to do.

This is my script:

https://drive.google.com/open?id=1vlptDnoS3XySh8bHgAxkSOYS_ujkBkrW

And this is what is happening;

Thank you! :<

it looks like you want to flip it when it’s facing left and right, If so you need to flip it when it hits 0 and 180 degrees instead of 90 and 270.