so i have made a simpel script that makes an enemy move torwards the player it works really well i just have a litle problem which is when i try to Transform.local scale my enemy so that the graphic will flip if hes changing direction it simply dosent work im using the same code that i used to flip my player when i press a A/D to move Right/Left by simply checking wether the Rigidiy body is moving right or left no idea why its not working neither did anyone that i asked and not quite sure what to google but gave a shot with no luck any help is appreciated Ty in advance.
Source Code
public bool EnemyOnPlayer;
private Rigidbody myrigidbody;
public PlayerController thePlayer;
// Use this for initialization
void Start () {
EnemyOnPlayer = false;
myrigidbody = FindObjectOfType<Rigidbody> ();
thePlayer = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update () {
if (EnemyOnPlayer == false)
{
transform.position = Vector3.MoveTowards (transform.position, thePlayer.transform.position, Time.deltaTime * move_speed);
}
if (myrigidbody.velocity.x > 0)
{
transform.localScale = new Vector3 (1f, 1f, 1f);
}
if (myrigidbody.velocity.x < 0)
{
transform.localScale = new Vector3 (-1f, 1f, 1f);
}
}