Why does my player change position when flipping?

I’ve attached a C# script to my player for movement and what not. When the player flips the position will move. It looks like the player was a turned page in a book. I’m unsure of how to fix this. Does anyone have any ideas?

Player.cs
void Flip()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;

    // Multiply the player's x local scale by -1.
    Vector3 theScale = transform.localScale;
    theScale.x *= -1;
    transform.localScale = theScale;
    Vector3 thePosition = transform.localPosition;
    transform.localPosition = thePosition;
}

Objects scale around their origin point. If the object’s origin is not centered (at least horizontally in your case since you are scaling on the x axis) the object will appear to “jump” when scaled. The object’s horizontal offset from it’s origin will scale also.

@jazzwil419 I know this is from 2015, but I wanted to add what I just discovered with this issue. I noticed that my sprite was behaving in the same manner described above (“turning like a page in a book”) when flipping axis. My camera was a child of my sprite object and followed the sprite around. It could be just the script attached that is causing the issue. The sprite flipped as desired once I removed the camera as a child. Hope this helps and good luck.