How do I flip the character when an object is infront/behind it?

I am making a 2d game and I have an enemy and player, I’m trying to make a Flip script that swaps two objects positions if another object is in front or behind it, but it just keeps flipping continuosly. Here’s what I have:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NearestLocation : MonoBehaviour
{
    public Transform enimy;

    public Transform otherPlr;

    public Vector3 tempPos;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    private void FixedUpdate()
    {
        if (otherPlr.position.x > enimy.position.x)
        {
            Swap(); return;
        }
        else if (otherPlr.position.x == enimy.position.x)
        {
            return;
        }
        else
        {
            Swap(); return;
        }
    }

    public void Swap()
    {
        tempPos = enimy.transform.position;

        enimy.transform.position = this.transform.position;

        this.transform.position = tempPos;
    }
}

Yes, you are swapping them whenever they dont have the same x coordinate. So they are swapping all the time.