How to let enemy change direction automatically ,when chasing player?

Hi, everyone.
I`m trying to make a 2d RPG. but I’m already stuck with coding my enemy.
For now ,my enemy can chase player , But it can change the direction automatically. I want my enemy can face right when it going right , can face left when it foing left. How can i achieve this.Please assist .
This is my code:

1900152–122503–AI.cs (1.18 KB)

Hello,

you need to add a rotation. Like transform.LookAt (target.position).

You can also take a look to some pathfinding plugin (A* Pathfinding Project, i like this one with a free version).
You will find ennemies AI example as lot of more stuff.