Sprite Flips into platform 2D

New to Unity development and I am having an issue where I come up to a wall and when I move my player away from the wall, the sprite flips into the foreground
158920-playeratwall.png

158921-playerflippedintoforeground.png

The code I am using to flip my sprite is:

private void FlipSprite()
{
m_FacingRight = !m_FacingRight;

    transform.Rotate(0f, 180f, 0f);
}

I have done another tutorial game and did not have this issue, so just wondering what I am doing wrong. Any assistance is greatly appreciated.

I need more informations, but it seems that that the pivot of the rotation is located near the feets of your character.


Alternatively you can use the Scale Component of the Transform of your object, by multiplying the x scaling by -1.