using UnityEngine;

public class FlipTowardPlayer : MonoBehaviour
{
    public float flipThreshold = 0.1f;
    private SpriteRenderer rend;

    void Start()
    {
        rend = GetComponent<SpriteRenderer>();
    }

    void Update()
    {
        Flip();
    }

    public void Flip()
    {
        if (Player.playerTransform.position.x > transform.position.x + flipThreshold)
        {
            rend.flipX = false;
        }
        else if (Player.playerTransform.position.x < transform.position.x - flipThreshold)
        {
            rend.flipX = true;
        }
    }
}

