In my top down 2d game i have a script to make my enemy always face the player however if the player is directly above or below the enemy the enemy becomes super thin and cant be seen, so instead i want the enemy to flip on the x axis depending on which side the player is on, so if the player is on his left he faces left but if the player on on his right he faces right. My current script is here
public float moveSpeed;
Transform target;
public float minDistance;
private float range;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
target = GameObject.FindWithTag("Player").transform;
range = Vector2.Distance(transform.position, target.position);
transform.LookAt(target.position);
transform.Rotate(new Vector3(0, 90, 0), Space.Self);
if (range < minDistance)
{
transform.position = Vector2.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
}
}
}